-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.ino
More file actions
150 lines (129 loc) · 3.19 KB
/
Copy pathmain.ino
File metadata and controls
150 lines (129 loc) · 3.19 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <neopixel.h>
SYSTEM_MODE(AUTOMATIC);
SYSTEM_THREAD(ENABLED);
#define PIXEL_PIN A3
#define PIXEL_COUNT 1
#define PIXEL_TYPE WS2812
enum Status { good, minor, major, maintenance};
Status status = Status::good;
Thread thread("status_thread", fetchStatus);
int green[3] = {80, 210, 10};
int red[3] = {215, 10, 0};
int yellow[3] = {200, 170, 0};
int blue[3] = {19, 105, 207};
system_tick_t lastThreadTime = 0;
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void fetchStatus(void);
void statusHandler(const char *event, const char *data);
void setup() {
Particle.subscribe("GH_STATUS/update", statusHandler, MY_DEVICES);
Serial.begin(9600);
strip.begin();
}
void loop() {
switch(status) {
case Status::good:
everythingsOK();
break;
case Status::maintenance:
maintaining();
break;
case Status::minor:
uhOh();
break;
case Status::major:
rip();
break;
}
}
void maintaining() {
strip.setPixelColor(0, blue[0], blue[1], blue[2]);
strip.setBrightness(30);
strip.show();
for (int i = 30; i <= 160; i++) {
strip.setPixelColor(0, blue[0], blue[1], blue[2]);
strip.setBrightness(i);
strip.show();
delay(10);
}
delay(800);
for (int i = 160; i >= 30; i--) {
strip.setPixelColor(0, blue[0], blue[1], blue[2]);
strip.setBrightness(i);
strip.show();
delay(10);
}
}
void everythingsOK() {
strip.setPixelColor(0, green[0], green[1], green[2]);
strip.setBrightness(30);
strip.show();
for (int i = 30; i <= 160; i++) {
strip.setPixelColor(0, green[0], green[1], green[2]);
strip.setBrightness(i);
strip.show();
delay(10);
}
delay(800);
for (int i = 160; i >= 30; i--) {
strip.setPixelColor(0, green[0], green[1], green[2]);
strip.setBrightness(i);
strip.show();
delay(10);
}
}
void uhOh() {
strip.setPixelColor(0, yellow[0], yellow[1], yellow[2]);
strip.setBrightness(30);
strip.show();
for (int i = 30; i <= 200; i++) {
strip.setPixelColor(0, yellow[0], yellow[1], yellow[2]);
strip.setBrightness(i);
strip.show();
delay(2);
}
for (int i = 200; i >= 30; i--) {
strip.setPixelColor(0, yellow[0], yellow[1], yellow[2]);
strip.setBrightness(i);
strip.show();
delay(2);
}
}
void rip() {
strip.setBrightness(200);
strip.setPixelColor(0, red[0], red[1], red[2]);
strip.show();
delay(200);
strip.setBrightness(0);
strip.setPixelColor(0, red[0], red[1], red[2]);
strip.show();
delay(200);
strip.setBrightness(200);
strip.setPixelColor(0, red[0], red[1], red[2]);
strip.show();
delay(200);
strip.setBrightness(0);
strip.setPixelColor(0, red[0], red[1], red[2]);
strip.show();
delay(700);
}
void fetchStatus() {
while (true) {
Particle.publish("status/check");
os_thread_delay_until(&lastThreadTime, 20000);
}
}
void statusHandler(const char *event, const char *data) {
if (data) {
Serial.println(data);
if (strcmp(data, "none") == 0) {
status = Status::good;
} else if (strcmp(data, "maintenance") == 0) {
status = Status::maintenance;
} else if (strcmp(data, "minor") == 0) {
status = Status::minor;
} else if (strcmp(data, "major") == 0) {
status = Status::major;
}
}
}