-
Notifications
You must be signed in to change notification settings - Fork 0
/
America_Lights.ino
311 lines (207 loc) · 5.58 KB
/
America_Lights.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 430
int lights[NUM_LEDS + 1];
int colorSelect = 0;
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2811, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
Sequence1();
Sequence2();
Sequence3();
}
void Sequence1() {
int pulse = 10;
int wait = 0;
int repeat = 1;
SetColor(255,0,0);
for (int i = 0; i < repeat; i++) {
ColorClimbUp(pulse, 255,0,0);
delay(wait);
ColorClimbUp(pulse, 255,255,255);
delay(wait);
ColorClimbUp(pulse, 0,0,255);
delay(wait);
};
ColorClimbUp(pulse, 255,0,0);
}
void Sequence2() {
int pulse = 5;
int wait = 0;
int repeat = 1;
SetColor(255,0,0);
for (int i = 0; i < repeat; i++) {
SparkleColorChange(pulse, 255,0,0);
delay(wait);
SparkleColorChange(pulse, 255,255,255);
delay(wait);
SparkleColorChange(pulse, 0,0,255);
delay(wait);
};
SparkleColorChange(pulse, 255,0,0);
}
void Sequence3() {
int pulse = 50;
int barWidth = 40;
int numColors = 3;
int repeat = (NUM_LEDS + 1);
CRGB colors[] = {
CRGB(0,255,0),
CRGB(255,255,255),
CRGB(0,0,255)
};
BarShift(pulse, barWidth, repeat, numColors, colors);
}
void MixedLights2(int red1, int green1, int blue1, int red2, int green2, int blue2, int red3, int green3, int blue3, int red4, int green4, int blue4, int red5, int green5, int blue5) {
for (int place = 0; place < NUM_LEDS; place = place+5) {
leds[place] = CRGB(green1, red1, blue1);
leds[place+1] = CRGB(green2, red2, blue2);
leds[place+2] = CRGB(green3, red3, blue3);
leds[place+3] = CRGB(green4, red4, blue4);
leds[place+4] = CRGB(green5, red5, blue5);
}
FastLED.show();
}
void MixedLights1(int red1, int green1, int blue1, int red2, int green2, int blue2, int red3, int green3, int blue3) {
for (int place = 0; place < NUM_LEDS; place = place+3) {
leds[place] = CRGB(green1, red1, blue1);
leds[place+1] = CRGB(green2, red2, blue2);
leds[place+2] = CRGB(green3, red3, blue3);
}
FastLED.show();
}
void ChristmasFade() {
int green = 0;
int red = 0;
int blue = 0;
int pulse = 2.5;
int wait = 1000;
SetColor(255, 0, 0);
delay(wait);
for (int i = 0; i < 255; i++) {
red--;
green++;
SetColor(red, green, blue);
delay(pulse);
}
SetColor(0, 255, 0);
delay(wait);
red = 0;
blue = 0;
green = 255;
for (int i = 0; i < 255; i++) {
red++;
blue++;
SetColor(red, green, blue);
delay(pulse);
}
SetColor(255, 255, 255);
delay(wait);
red = 255;
green = 255;
blue = 255;
for (int i = 0; i < 255; i++) {
green--;
blue--;
SetColor(red, green, blue);
delay(pulse);
}
delay(wait);
}
void SetThreeColors(int topRed, int topGreen, int topBlue, int midRed, int midGreen, int midBlue, int bottomRed, int bottomGreen, int bottomBlue) {
int sectionDivider = NUM_LEDS / 3;
//bottom
for(int place = 0; place <= sectionDivider; place++) {
leds[place] = CRGB(bottomGreen, bottomRed, bottomBlue);
}
FastLED.show();
//middle
for(int place = sectionDivider; place <= sectionDivider * 2; place++) {
leds[place] = CRGB(midGreen, midRed, midBlue);
}
FastLED.show();
//top
for(int place = sectionDivider * 2; place <= (sectionDivider * 3); place++) {
leds[place] = CRGB(topGreen, topRed, topBlue);
}
FastLED.show();
}
void SetColor(int red, int green, int blue) {
//fill
for(int place = 0; place < NUM_LEDS; place++) {
leds[place] = CRGB(green, red, blue);
}
FastLED.show();
}
void ColorSwitch(int initialRed, int initialGreen, int initialBlue, int newRed, int newGreen, int newBlue) {
//fill
for(int place = 0; place < NUM_LEDS; place++) {
leds[place] = CRGB(initialGreen, initialRed, initialBlue);
}
FastLED.show();
//newColor
for(int place = 0; place < NUM_LEDS; place++) {
leds[place] = CRGB(newGreen, newRed, newBlue);
}
FastLED.show();
}
void ColorClimbUp(int pulse, int red, int green, int blue) {
for(int place = 0; place < NUM_LEDS; place++) {
leds[place] = CRGB(green, red, blue);
FastLED.show();
delay(pulse);
}
}
void ColorClimbDown(int pulse, int red, int green, int blue) {
for(int place = NUM_LEDS; place >= 0; place--) {
leds[place] = CRGB(green, red, blue);
FastLED.show();
delay(pulse);
}
}
void SparkleColorChange(int pulse, int red, int green, int blue) {
//sparkle
for (int i = 0; i < NUM_LEDS; i++) {
lights[i] = i;
}
size_t n = sizeof(lights) / sizeof(lights[0]);
for (size_t i = 0; i < n - 1; i++) {
size_t j = random(0, n - i);
int t = lights[i];
lights[i] = lights[j];
lights[j] = t;
}
for(int i = 0; i < NUM_LEDS; i++) {
int place = lights[i];
Serial.println(place);
leds[place] = CRGB(green, red, blue);
delay(pulse);
FastLED.show();
}
}
void BarShift(
int pulse, int barWidth, int repeat,
int numColors, CRGB colors[]) {
// Ensure numColors is greater than 0
if (numColors < 1) return;
// Repeat x amount of times
for (int i = 0; i < repeat; i++) {
// Set the LEDs with alternating bars
for (int j = 0; j < NUM_LEDS; j++) {
// Use floor division for color index calculation
int colorIndex = (int)floor((float)(j - i) / barWidth) % numColors;
// Handle negative mod correctly
if (colorIndex < 0) {
colorIndex += numColors;
}
// Set the corresponding color
leds[j] = colors[colorIndex];
}
// Show the result and delay for pulse timing
FastLED.show();
delay(pulse);
}
}