forked from cjb/lilypad-email-shirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lilypad.pde
55 lines (51 loc) · 1.47 KB
/
lilypad.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* lilypad.pde
* Author: Chris Ball <[email protected]>
* Function: Take a number from a serial port, and display it on LEDs.
* URL: http://github.com/cjb/lilypad-email-tshirt/
* License: GPLv2+ or later, at your option.
*/
void setup() {
Serial.begin(115200);
for (int i = 12; i <= 18; 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;
}
digitalWrite(12, HIGH && (numMails & B1000000));
digitalWrite(13, HIGH && (numMails & B0100000));
digitalWrite(14, HIGH && (numMails & B0010000));
digitalWrite(15, HIGH && (numMails & B0001000));
digitalWrite(16, HIGH && (numMails & B0000100));
digitalWrite(17, HIGH && (numMails & B0000010));
digitalWrite(18, HIGH && (numMails & B0000001));
}