-
Notifications
You must be signed in to change notification settings - Fork 0
/
bikeshare_and_wamata_serial_responder.ino
236 lines (189 loc) · 5.58 KB
/
bikeshare_and_wamata_serial_responder.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
int incomingByte; //variable to read incoming serial data
String str;
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the string up until the 'Z' char marks the end
str = Serial.readStringUntil('Z');
//bikeshare comes first
//first station
if (str.indexOf('A') >= 0) {
strip.setPixelColor(0, 255, 0, 0);
}
if (str.indexOf('B') >= 0) {
strip.setPixelColor(0, 255, 255, 0);
}
if (str.indexOf('C') >= 0) {
strip.setPixelColor(0, 128, 255, 0);
}
if (str.indexOf('D') >= 0) {
strip.setPixelColor(0, 0, 255, 0);
}
//second station
if (str.indexOf('E') >= 0) {
strip.setPixelColor(1, 255, 0, 0);
}
if (str.indexOf('F') >= 0) {
strip.setPixelColor(1, 255, 255, 0);
}
if (str.indexOf('G') >= 0) {
strip.setPixelColor(1, 128, 255, 0);
}
if (str.indexOf('H') >= 0) {
strip.setPixelColor(1, 0, 255, 0);
}
//third station
if (str.indexOf('I') >= 0) {
strip.setPixelColor(2, 255, 0, 0);
}
if (str.indexOf('J') >= 0) {
strip.setPixelColor(2, 255, 255, 0);
}
if (str.indexOf('K') >= 0) {
strip.setPixelColor(2, 128, 255, 0);
}
if (str.indexOf('L') >= 0) {
strip.setPixelColor(2, 0, 255, 0);
}
//fourth station
if (str.indexOf('M') >= 0) {
strip.setPixelColor(3, 255, 0, 0);
}
if (str.indexOf('N') >= 0) {
strip.setPixelColor(3, 255, 255, 0);
}
if (str.indexOf('O') >= 0) {
strip.setPixelColor(3, 128, 255, 0);
}
if (str.indexOf('P') >= 0) {
strip.setPixelColor(3, 0, 255, 0);
}
//fifth station
if (str.indexOf('Q') >= 0) {
strip.setPixelColor(4, 255, 0, 0);
}
if (str.indexOf('R') >= 0) {
strip.setPixelColor(4, 255, 255, 0);
}
if (str.indexOf('S') >= 0) {
strip.setPixelColor(4, 128, 255, 0);
}
if (str.indexOf('T') >= 0) {
strip.setPixelColor(4, 0, 255, 0);
}
// now wmata
// yellow is second because if both light should be
// yellow b/c yellow goes to the airport and is
// likely more important
//first light (at station)
// first yellow train
if (str.indexOf('i') >= 0) {
strip.setPixelColor(5, 255, 255, 0);
}
//first green train
else if (str.indexOf('a') >= 0) {
strip.setPixelColor(5, 255, 0, 0);
}
// second yellow train
else if (str.indexOf('m') >= 0) {
strip.setPixelColor(5, 255, 255, 0);
}
//second green train
else if (str.indexOf('e') >= 0) {
strip.setPixelColor(5, 255, 0, 0);
}
// turns off the LED if nothing here
else {
strip.setPixelColor(5, 0, 0, 0);
}
//second light (leave now)
// first yellow train
if (str.indexOf('j') >= 0) {
strip.setPixelColor(6, 255, 255, 0);
}
//first green train
else if (str.indexOf('b') >= 0) {
strip.setPixelColor(6, 255, 0, 0);
}
// second yellow train
else if (str.indexOf('n') >= 0) {
strip.setPixelColor(6, 255, 255, 0);
}
//second green train
else if (str.indexOf('f') >= 0) {
strip.setPixelColor(6, 255, 0, 0);
}
// turns off the LED if nothing here
else {
strip.setPixelColor(6, 0, 0, 0);
}
//third light (coming soon)
// first yellow train
if (str.indexOf('k') >= 0) {
strip.setPixelColor(7, 255, 255, 0);
}
//first green train
else if (str.indexOf('c') >= 0) {
strip.setPixelColor(7, 255, 0, 0);
}
// second yellow train
else if (str.indexOf('o') >= 0) {
strip.setPixelColor(7, 255, 255, 0);
}
//second green train
else if (str.indexOf('g') >= 0) {
strip.setPixelColor(7, 255, 0, 0);
}
// turns off the LED if nothing here
else {
strip.setPixelColor(7, 0, 0, 0);
}
//fourth light (long way off)
// first yellow train
if (str.indexOf('l') >= 0) {
strip.setPixelColor(8, 255, 255, 0);
}
//first green train
else if (str.indexOf('d') >= 0) {
strip.setPixelColor(8, 255, 0, 0);
}
// second yellow train
else if (str.indexOf('p') >= 0) {
strip.setPixelColor(8, 255, 255, 0);
}
//second green train
else if (str.indexOf('h') >= 0) {
strip.setPixelColor(8, 255, 0, 0);
}
// turns off the LED if nothing here
else {
strip.setPixelColor(8, 0, 0, 0);
}
}
//pushes the changes to the LEDs
strip.show();
}