-
Notifications
You must be signed in to change notification settings - Fork 0
/
holidayLights.ino
54 lines (47 loc) · 1.2 KB
/
holidayLights.ino
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
/*
This sketch controls a string of holiday lights using
the LigthBlue Bean and the iOS app LightBlue.
This code is in the public domain.
*/
// The control inputs we will use from LightBlue
#define button1 13
#define button2 14
#define button3 15
void setup()
{
Serial.begin();
Serial.setTimeout(5);
// Set the pins connected to the holiday lights to OUTPUT
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
}
void loop() {
// Check for serial messages from LightBlue
char buffer[64];
size_t length = 64;
length = Serial.readBytes(buffer, length);
if ( length > 0 )
{
for (int i = 0; i < length - 1; i += 2 )
{
// Check if button1 has been pressed or released...
if ( buffer[i] == button1 )
{
// If the button is held down, buffer[i+1] will be 0
// If it's released, buffer[i+1] is 1
// Set pin 0 to 1 when the button is held down
// and to 0 when released
digitalWrite(0,1-buffer[i+1]);
}
else if ( buffer[i] == button2 )
{
digitalWrite(1,1-buffer[i+1]);
}
else if ( buffer[i] == button3 )
{
digitalWrite(2,1-buffer[i+1]);
}
}
}
}