Last active
December 27, 2015 20:59
-
-
Save flyingoctopus/7388948 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
Serial.begin(115200); | |
for (int i = 1; i <= 12; i++) { | |
/* Set pins 12-18 to output, and strobe them to test. */ | |
pinMode(i, OUTPUT); | |
digitalWrite(i, HIGH); | |
delay(100); | |
digitalWrite(i, LOW); | |
} | |
} | |
void loop() | |
{ | |
int i = 0; | |
int numMails = 0; | |
delay(2000); | |
switch (Serial.available()) { | |
/* Serial.available() is the number of bytes waiting. Convert from | |
* ASCII val to an int. Intentional switch-case fall through below. | |
*/ | |
case 3: | |
numMails = Serial.read(); | |
numMails -= 48; | |
numMails *= 10; | |
case 2: | |
numMails += Serial.read(); | |
numMails -= 48; | |
numMails *= 10; | |
case 1: | |
numMails += Serial.read(); | |
numMails -= 48; | |
break; | |
default: | |
/* If >3 chars, just clear out the incoming buffer. */ | |
while (Serial.available()) | |
Serial.read(); | |
return; | |
} | |
for (int i = 1; i <= 12; i++) { | |
// strobe! | |
digitalWrite(i, HIGH); | |
delay(100); // this delays the strobe | |
digitalWrite(i, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment