-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuildlight.ino
69 lines (61 loc) · 1.5 KB
/
buildlight.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
int greenLED = D6;
int yellowLED = D3;
int redLED = D0;
boolean green_active = true;
boolean yellow_active = true;
boolean red_active = true;
// We start with the setup function.
void setup() {
// Setup pins
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(redLED, OUTPUT);
// Subscribe to events
Particle.subscribe("build_state", stateHandler);
Particle.publish("ready", "true", PRIVATE);
}
void loop() {
// Is the green light on?
if (green_active) {
digitalWrite(greenLED, HIGH);
} else {
digitalWrite(greenLED, LOW);
}
// Is the red light on?
if (red_active) {
digitalWrite(redLED, HIGH);
} else {
digitalWrite(redLED, LOW);
}
// Is the yellow light active?
if (yellow_active) {
// This should flash the light every second
if (millis() % 2000 > 1000) {
digitalWrite(yellowLED, HIGH);
} else {
digitalWrite(yellowLED, LOW);
}
} else {
digitalWrite(yellowLED, LOW);
}
}
void stateHandler(const char *event, const char *data)
{
if (strcmp(data, "passing") == 0) {
green_active = true;
yellow_active = false;
red_active = false;
} else if (strcmp(data, "passing-building") == 0) {
green_active = true;
yellow_active = true;
red_active = false;
} else if (strcmp(data, "failing-building") == 0) {
green_active = false;
yellow_active = true;
red_active = true;
} else if (strcmp(data, "failing") == 0) {
green_active = false;
yellow_active = false;
red_active = true;
}
}