-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfxFunctions.ino
344 lines (259 loc) · 7.92 KB
/
fxFunctions.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// These are basically all the "mode" function calls
// So any game logic should be built into these, including
// passing any "timing" functions from over the network I guess
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}
//
//
//void standby() {
// // alternate amber and blue
// // maybe we should make it "twinkle" instead as the standby?
// if ((gHue % 8) == 0) {
//
// // odd
// for (uint8_t i = 0; i < NUM_LEDS - 1; i++) {
// leds[i] = CRGB::PaleGoldenrod;
// leds[i + 1] = CRGB::LightSteelBlue;
// }
// }
// else {
// // even
// for (uint8_t i = 0; i < NUM_LEDS - 1; i++) {
// leds[i + 1] = CRGB::PapayaWhip;
// leds[i] = CRGB::LightSteelBlue;
// }
// }
//}
/// accel game
uint8_t maxLevel = 0;
int gameTimer = 0;
void accelGame() {
// THE BUILD UP
if (maxLevel < 12 ) {
if (latch) {
tone(9, emajor[maxLevel], 300);
delay(50);
noTone(9);
maxLevel++;
gameTimer = 0;
} else {
gameTimer++;
if (gameTimer > 15 && maxLevel > 0) {
maxLevel--;
tone(9, emajor[maxLevel], 300);
delay(50);
noTone(9);
gameTimer = 0;
}
}
fill_solid( leds, 12, CRGB(98, 46, 50));
if (maxLevel > 12) {
maxLevel = 12;
}
for (int i = 0; i < maxLevel; i++) {
leds[i] = CRGB(0, 0, 255);
}
}
}
void mushroom() {
//fill_solid(leds, 12, CHSV(292, 100, 40));
// if (gHue > 21 && gHue < 33) {
uint8_t toLight = -(gHue % 11) + 11;
leds[toLight] = CHSV( gHue,200, 255); // random shade of purple
// }
nscale8( leds, NUM_LEDS, 240); // slow fade out
// base colour
for (uint8_t i = 0; i< NUM_LEDS; i++) {
leds[i] |= CHSV(292, 100, 40);
}
}
void pinwheel() {
// fill the others are deterministic color
uint8_t hueResult = (gHue * 2) + map(chuteID, 0, 12, 0, 255);
fill_solid( leds, 12, CHSV(hueResult , 200, 255));
}
void fireworks() {
// ghue = colour of the explosion
// more of a spiral, not fireworks
// create a blink as it progresses outwards -- every cycle we alternate "value" from 0 to 1
fill_solid( leds, 12, CRGB::Black);
// Spiral 1
if (gHue % 12 == chuteID) {
uint8_t toLight = constrain(map(gHue, 0, 255, 11, 0), 0, 11);
leds[toLight] = CHSV(gHue, 255, 255); // random shade of green
}
// Spiral 2
uint8_t gHueAlt = gHue + 120;
if (gHueAlt % 12 == chuteID) {
uint8_t toLight = constrain(map(gHueAlt, 0, 255, 11, 0), 0, 11);
leds[toLight] = CHSV(gHue * 2, 255, 255); // random shade green
}
// base colour
for (uint8_t i = 0; i< NUM_LEDS; i++) {
leds[i] |= CRGB(0, 20, 0);
}
// if ( (millis() - (fxTimer)) > fxSpeed) {
//
// //uint8_t toLight = -(gHue % 11) + 11;
// uint8_t toLight = map(((gHue + (chuteID * 21)), 0, 512, 11, 0);
// Serial.println(toLight);
//
// fxTimer = millis();
//
//
//
// }
//nscale8_video( leds, NUM_LEDS, 10); // not quite to black?
}
void ocean() {
if ( millis() - (fxTimer) > 50) {
// shuffle everything in torwards the middle, but only once and a while
for (uint8_t i = NUM_LEDS - 1; i > 0; i--) {
leds[i] = leds[i - 1];
}
fxTimer = millis();
}
if (latch) {
leds[0] = CRGB::White;
tone(9, NOTE_G4, 35);
delay(35);
tone(9, NOTE_C4, 35);
delay(35);
tone(9, NOTE_D4, 35);
delay(35);
noTone(9);
} else {
leds[0] = CRGB::Blue;
}
}
void starfield () {
// this is more of a "warp speed" type effect
if ( millis() - (fxTimer) > fxSpeed) {
int randomStar = random8(chuteID, 255);
if ((randomStar % 2) == 0) {
randomStar = 0;
}
leds[NUM_LEDS - 1] = CRGB(randomStar, randomStar, randomStar);
for (uint8_t i = 0; i < NUM_LEDS - 1; i++) {
leds[i] = leds[i + 1];
}
fxTimer = millis();
}
}
void sparkle() {
// random colours sparkles
int twinkrate = 100; // The higher the value, the lower the number of twinkles.
uint8_t thisdelay = 10; // A delay value for the sequence(s).
uint8_t thisfade = 5; // How quickly does it fade? Lower = slower fade rate.
uint8_t thishue = 50; // The hue.
uint8_t thissat = 100; // The saturation, where 255 = brilliant colours.
uint8_t thisbri = 255; // Brightness of a sequence.
bool randhue = 1; // Do we want random colours all the time? 1 = yes.
if (twinkrate < NUM_LEDS) twinkrate = NUM_LEDS; // Makes sure the twinkrate will cover ALL of the LED's as it's used as the maximum LED index value.
int i = random16(twinkrate + chuteID); // A random number based on twinkrate. Higher number => fewer twinkles.
if (randhue) thishue = random16(0, 255); // Randomize every LED if TRUE
if (i < NUM_LEDS) leds[i] = CHSV(thishue, thissat, thisbri); // Only the lowest probability twinkles will do. You could even randomize the hue/saturation.
for (int j = 0; j < NUM_LEDS; j++) leds[j].fadeLightBy(thisfade); // Use the FastLED fade method.
}
void test() {
// strand ID
if (gHue > 0 && gHue < 50) {
fill_solid( leds, 12, CRGB::Black);
fill_solid( leds, chuteID, CRGB(255, 255, 255));
}
// for sync
if (gHue > 50 && gHue < 99) {
fill_solid( leds, 12, CRGB::Black);
fill_solid( leds, (gHue % 12), CRGB(120, 120, 120));
}
if (gHue > 100 && gHue < 149) {
fill_solid( leds, 12, CRGB::Black);
fill_solid( leds, 12, CRGB(255, 0, 0));
}
if (gHue > 150 && gHue < 199) {
fill_solid( leds, 12, CRGB::Black);
fill_solid( leds, 12, CRGB(0, 255, 0));
}
if (gHue > 200 && gHue < 255) {
fill_solid( leds, 12, CRGB::Black);
fill_solid( leds, 12, CRGB(0, 0, 255));
}
}
void powerOff() {
if ( (millis() - (fxTimer)) > 1000) {
if (powerOn) {
powerTimer--;
tone(9, 200);
delay (100);
noTone(9);
}
fxTimer = millis();
}
fill_solid( leds, 12, CRGB::Black);
for (int i = 0; i < powerTimer; i++) {
fill_solid( leds, i, CRGB::White);
}
Serial.println(powerTimer);
if (powerTimer < 1) {
powerOn = 0;
}
}
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue*4, 7);
}
//
//void juggle() {
// // eight colored dots, weaving in and out of sync with each other
// fadeToBlackBy( leds, NUM_LEDS, 20);
// byte dothue = 0;
// for ( int i = 0; i < 8; i++) {
// leds[beatsin16(i + 7, 0, NUM_LEDS)] |= CHSV(dothue, 200, 255);
// dothue += 32;
// }
//}
void confetti()
{
fadeToBlackBy( leds, NUM_LEDS, 10);
if ( millis() - (fxTimer) > fxSpeed) {
// random colored speckles that blink in and fade smoothly
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
fxTimer = millis();
}
}
//
void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16(13, 0, NUM_LEDS);
leds[pos] += CHSV( gHue, 255, 192);
}
// 1/6, 2/7, 3/8, 4/9, 5/10
void stix() {
uint8_t fast = gHue*8;
uint8_t angle = map(fast, 0, 255, 1, 11);
if (chuteID == angle ) {
fill_solid( leds, 12, CHSV(gHue, 150, 220));
}
else {
fadeToBlackBy( leds, NUM_LEDS, 20);
}
}
//
//void bpm()
//{
// // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
// uint8_t BeatsPerMinute = 62;
// CRGBPalette16 palette = PartyColors_p;
// uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
// for ( int i = 0; i < NUM_LEDS; i++) { //9948
// leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
// }
//}