-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreamery.ino
1397 lines (1240 loc) · 33.5 KB
/
Creamery.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <SPI.h>
#include <Adafruit_WS2801.h>
#include <TrueRandom.h>
#define DATAPIN 2 // Data pin for serial communication to shift registers
#define CLOCKPIN 3 // Clock pin for serial communication to shift registers
// Grid DEF & Vars
#define panelsX 12
#define panelsY 3
#define pixelsX 1
#define pixelsY 1
#define pixelsTotal 36
// Instantiate Controller. Num Pix Automatically Generated.
Adafruit_WS2801* strip = new Adafruit_WS2801(pixelsTotal, DATAPIN, CLOCKPIN);
// Alignment,Direction,Pattern Enumeration
enum {asc,desc, horizontal,vertical, strand,panel,mirrored};
uint16_t orientation = vertical;
uint16_t direction = desc;
// nodeTimeStamps becomes colorPallette
uint32_t colors[pixelsTotal];
uint32_t colors_future[pixelsTotal];
uint8_t color_start[pixelsTotal][3]; // transition arrays. /// super testing
uint8_t color_end[pixelsTotal][3];
uint8_t increments[pixelsTotal][3];
uint8_t inc_a,inc_b,inc_c;
extern boolean DEBUG = 0; // Flag for debugging.
extern boolean eflag = 1; // flag so that we can trigger only once per effect.
uint8_t verbose = 0; // Flag for verbose debugging.
// Transition Vars
boolean will_transition = 1;
boolean transitioning = 0;
boolean updateInterval = 1;
boolean full_or_wheel = 0; // 0 for full color, 1 for wheel color. ///Not working yet...
// CTRL Vars
long
now,
then,
iduration,
pduration,
autoPilot;
uint16_t /// set defaults
iter,
itermax,
interval,
intervalCount,
frequency,
sustain,
density,
decay,
phase,
selector,
mode;
uint16_t transition_steps = 32;
uint16_t current_transition_step = 0;
uint32_t
primary,
secondary,
tertiary;
// Serial Input Vars
char messageBuffer[8]; // Can't forsee more than 8c*s as long as we stay away from long pattern titles.
uint8_t bufferIndex = 0; // This global manages the buffer index.
uint8_t readMode = 0; // Wait
/// at some point we may need to create a function that returns pixelsTotal based on mode (panel/mirror/etc)
// fill the dots one after the other with said color
// good for testing purposes
void flavorWipe() {
if (DEBUG && eflag) {Serial.println("Beginning Effect flavorWipe...");eflag=0;}
itermax = pixelsTotal;
q(iter, primary);
}
// Just fill the strand with a color
void flavorFill() {
if (DEBUG && eflag) {Serial.println("Beginning Effect flavorFill...");eflag=0;}
for (int i=0; i < pixelsTotal; i++) {
q(i, primary);
}
}
void rainbow() {
if (DEBUG && eflag) {Serial.println("Beginning Effect rainbow...");eflag=0;}
frequency = 200; /// unhardcode
itermax = 255;
for (int i=0; i < pixelsTotal; i++) {
q(i, Wheel( (iter) % 255));
}
}
void rainbowCycle() {
if (DEBUG && eflag) {Serial.println("Beginning Effect rainbowCycle...");eflag=0;}
frequency = 20; /// unhardcode
itermax = 255;
for (int i=0; i < pixelsTotal; i++) {
// tricky math! we use each pixel as a fraction of the full 96-color wheel
// (thats the i / strip.numPixels() part)
// Then add in j which makes the color go around per pixel
// the % 96 is to make the wheel cycle around
q(i, Wheel( ((i * 256 / pixelsTotal) + iter) % 256) );
}
}
// Moves colors along the strand. Frequency of 200 or lower is a nice pace. Should be rapid and exciting
void colorCycle() {
if (DEBUG && eflag) {Serial.println("Beginning Effect colorCycle...");eflag=0;}
frequency = 200; /// unhardcode
// itermax = 255;
// if (eflag) { colors_future = colors; }
// Get a new random color.
if (full_or_wheel) {colors_future[0] = RandomColor();} else {colors_future[0] = RandomWheel();}
for (int i=0; i < pixelsTotal; i++) {
// Move the chain along but don't go to far.
if (i < pixelsTotal-1) {
colors_future[i+1] = colors[i];
}
// set the future colors.
q(i,colors_future[i]);
}
}
void colorCycleFade() {
if (DEBUG && eflag) {Serial.println("Beginning Effect colorCycleFade...");eflag=0;}
frequency = 200; /// unhardcode
// itermax = 255;
// if (eflag) { colors_future = colors; }
// Get a new random color.
// will_transition = 1;
if (!will_transition) {
colors_future[0] = RandomWheel();
for (int i=0; i < pixelsTotal; i++) {
// Move the chain along but don't go to far.
if (i < pixelsTotal-1) {
colors_future[i+1] = colors[i];
}
// set the future colors.
// q(i,colors_future[i]);
}
will_transition = 1;
} else {
transition();
}
if (current_transition_step == transition_steps) will_transition = 0;
}
void sparkle(){
if (DEBUG && eflag) {Serial.println("Beginning Effect sparkle...");eflag=0;}
uint32_t bg = secondary;
/*//// We need to account for sustain and frequency for this...
frequency would need to be short short and then checked inside this loop
then decay is used to determine the overall division of fade out...
setup an array for the pixels that are 'active'?
*/
int pos;
//Set all pixels to bg
for(int i=0; i < pixelsTotal; i++ ) {
//Set color
q(i, bg);
}
//Pick at random x number of times (x = density)
for(int r=0; r < density; r++ ) {
//Pick pixel
pos = R(0,pixelsTotal);
q(pos, primary);
}
}
void (*menu[])() = {flavorWipe,flavorFill,rainbow,rainbowCycle,colorCycleFade,colorCycle,sparkle};
uint8_t menu_count = sizeof(menu)/2;
void decompose(uint16_t p) {
if (p<pixelsTotal) {
color_start[p][0] = extractRed(colors[p]);
color_start[p][1] = extractGreen(colors[p]);
color_start[p][2] = extractBlue(colors[p]);
color_end[p][0] = extractRed(colors_future[p]);
color_end[p][1] = extractGreen(colors_future[p]);
color_end[p][2] = extractBlue(colors_future[p]);
// if (color_start[p][0] < color_start[p][0])
// if (color_start[p][0] < color_start[p][0])
// if (color_start[p][0] < color_start[p][0])
inc_a = (color_end[p][0] - color_start[p][0]);
inc_b = (color_end[p][1] - color_start[p][1]);
inc_c = (color_end[p][2] - color_start[p][2]);
if (inc_a != 0) {increments[p][0] = inc_a / transition_steps;} else { increments[p][0] = 0;} //// 32 is the magic transition step number
if (inc_b != 0) {increments[p][1] = inc_b / transition_steps;} else { increments[p][1] = 0;}
if (inc_c != 0) {increments[p][2] = inc_c / transition_steps;} else { increments[p][2] = 0;}
// Serial.print(p);
// Serial.println(" ------ decomp");
// for(int j=0; j<3; j++){
// Serial.println(increments[p][j]);
// }
// increments[p][0] = (color_end[p][0] - color_start[p][0]) / transition_steps; //// 32 is the magic transition step number
// increments[p][1] = (color_end[p][1] - color_start[p][1]) / transition_steps;
// increments[p][2] = (color_end[p][2] - color_start[p][2]) / transition_steps;
// delay(2000); ///
}
}
void recompose(uint16_t p) {
if (p<pixelsTotal) {
colors[p] = color(color_start[p][0],color_start[p][1],color_start[p][2]);
}
}
void transition() {
if (will_transition) {
for(int i=0; i<pixelsTotal; i++){
// Serial.print(i);
// Serial.println(" ------");
decompose(i);
}
will_transition = 0;
current_transition_step = 0;
}
for(int i=0; i<pixelsTotal; i++){
color_start[i][0] += increments[i][0];
color_start[i][1] += increments[i][1];
color_start[i][2] += increments[i][2];
colors[i] = color(color_start[i][0],color_start[i][1],color_start[i][2]);
current_transition_step++;
// Serial.print(i);
// Serial.println(" trans ------");
// for(int j=0; j<3; j++){
// Serial.println(increments[i][j]);
// }
}
// delay(1000);
}
// #setup
void setup()
{
Serial.begin(9600);
updatePrimary(color(255,255,255));
secondary = color(255,255,255);
tertiary = color(255,255,255);
strip->begin();
strip->show();
frequency = 260;
intervalCount = 1;
interval = 0;
iter = 0;
itermax = pixelsTotal;
selector = 5;
DEBUG = 1;
verbose = 0;
if (DEBUG) statusUpdate();
}
void loop() {
now = millis(); // This moment is beautiful.
if (now >= then+frequency) {
then = now;
crank(); // Select mode based on information.
churn(); // Sustains flame based on each pin's last timestamp and current frameDuration
pour(); // Send the 1011 and let the people have some fun.
taste();
}
// We are polling the serial connection.
while(Serial.available() > 0) {
char x = Serial.read();
serialRouting(x);
}
}
void rest() {
// never happens.
}
void crank() {
// this is where we move forward.
// update mode, interval, phase etc.
if (iter < itermax) {
iter += 1;
} else {
iter = 0;
interval++;
}
}
void churn() {
// this is where things change.
// Update based on interval and phase.
// This is where we switch on interval.
if (interval >= intervalCount) { /// This may belong in crank().
interval = 0;
// selector = R(0,menu_count-1);
// selector = 4; ///hardcoding.
/// we need to account for user input changing the selector in the middle.
/// Really we are supposed to have selector choose the
/// settings for the effect and then declare the effect
/// identifier within the selector statement.
/// perhaps with an enum or via function.
// if (effectComplete) choreography();
/// This goes into the project file as choreography() or something;
switch (selector) {
case 0:
// flavorWipe()
intervalCount = 1;
frequency = 60;
itermax = pixelsTotal;
updatePrimary(RandomWheel());
break;
case 1:
// flavorFill()
intervalCount = 1;
itermax = pixelsTotal;
updatePrimary(RandomWheel());
// itermax =
// intervalCount = 3;
break;
case 2:
// rainbow()
intervalCount = 1;
itermax = 255;
// updatePrimary(RandomWheel());
break;
case 3:
// rainbowCycle()
intervalCount = 3;
itermax = 255;
break;
case 4:
intervalCount = 1;
frequency = 150;
break;
case 5:
// will_transition = 1;
intervalCount = 1;
// sparkle()
itermax = 30;
density = R(1,pixelsTotal);
decay = 20;
updatePrimary(RandomWheel());
updateSecondary(color(0,0,0));
break;
default:
// do something... Reset probably. //This is a hack for not knowing why selector is going out of bounds
updateAssorted();
// selector = R(0,sizeof(menu)-1);
interval = 100;
}
if (DEBUG) {eflag=1;statusUpdate();}
}
(*menu[selector])();
// if (transitioning) transition();
// else (*menu[selector])(); // Magic array function call.
// if (will_transition) {
// transitioning = 1;
// }
}
void pour() {
// this is where we lay the goods.
for(int i=0; i<pixelsTotal; i++){
strip->setPixelColor(i,colors[i]);
}
}
void taste() {
// this is where the magic happens.
// if (VERBOSE && DEBUG) {
// Serial.println("Pouring deliciousness ...");
// }
// this is where we actually go live!
strip->show();
}
// for(int i = 0; i < n; i++) // larger values of 'n' will give a smoother/slower transition.
// {
// Rnew = Rstart + (Rend - Rstart) * i / n;
// Gnew = Gstart + (Gend - Gstart) * i / n;
// Bnew = Bstart + (Bend - Bstart) * i / n;
// // set pixel color here
// }
//
// virtual void q() =0;
void q(uint16_t pos, uint32_t c) {
int p;
// In here we need to be able to check the orientation, mode, and then check to see if we are compositing two effects.
// flag for overlay / transition.
if (mode == strand) {
/// Still need orientation and direction statements here
p = pos;
} else
if (mode == mirrored) { /// Mirror mode should be seperate and augment any of the other modes. ie any mode could be mirrod.
// left/right mirror mode.
// p = mirror(pos);
} else
if (mode == panel) { // Make each panel do the same thing.
// Serial.println(orientation);
// Serial.print("--- ");Serial.println(pos);
if (orientation == horizontal) {
for (int i=0;i<pixelsTotal/panelsX;i++) {
p = pixelsY*pos+i;
// p = pixelsY*pos+i;
// strip->setPixelColor(p, c);
// Serial.println(p);
}
} else if (orientation == vertical) {
for (int i=0;i<pixelsTotal/pixelsY;i++) {
// p = (i%2) ? (panelsX*i)+(pixelsY-1)-(pos) : (i*panelsX)+(pos);
// This one might be better....
p = (i%2) ? (pixelsY*i)+(pixelsY-1)-(pos) : (i*pixelsY)+(pos);
// strip->setPixelColor(p,c);
// Serial.println(p);
}
}
} else {
p = pos;
}
if (transitioning) {
/// -- This defintiely goes somewhere else. Pour()?
// change C based on some color maths.
// compare color array 1 against color array 2
// should we do this somewhere else? like pour() or churn()?
// then we would always load up a color array here
// and then setPixelColor() in a foreach later
colors_future[p] = c;
} else {
colors[p] = c;
}
// strip->setPixelColor(p,c);
}
// Serial Functions
void serialRouting(char x) {
//Flags, set read mode., begin
if ( x == '!' ) { readMode = 1; } //Set Selector
else if ( x == '@' ) { readMode = 2; } //Set Frequency
else if ( x == '#' ) { readMode = 3; } //Set
else if ( x == '+' ) { readMode = 4; } //Shift Register IDs, separated by comma (no whitespace)
else if ( x == '-' ) { readMode = 5; } //Shift Register IDs, separated by comma (no whitespace)
else if ( x == '~' ) { readMode = 6; } //System Mode
else if ( x == '*' ) { readMode = 7; } //System Mode
// else if ( x == '/' ) { getFiles(); }
// else if ( x == '?' ) { statusUpdate(); }
//Add custom flags here...
//Finish up
else if (x == '.') { //...
//This will update the global variables accordingly.
switch(readMode){
case 1: setSelector(); break;
// case 2: setDuration(); break;
// case 3: setInterval(); break;
// case 4: setValveOn(); break;
// case 5: setValveOff(); break;
// case 6: setMode(); break;
// case 7: setActive(); break;
default: break;
}
// lastSerialCMD = now; //Used for switching to autoPilot
readMode = 0; //We're done reading. (until another.)
autoPilot = false;
bufferIndex = 0;
}
else { messageBuffer[bufferIndex++] = x; } //Magic.
}
void setSelector() {
// if (messageBuffer) /// do we need checking here? it's all going to change eventually.
/// Also we should probably reset our interval here.
selector = atoi(messageBuffer);
if (DEBUG) Serial.print("User updated selector: ");Serial.println(selector);
intervalCount = 0;
resetMessageBuffer();
}
void resetMessageBuffer(){
memset( messageBuffer, '\0', sizeof(messageBuffer) );
}
void statusUpdate() {
// Serial.print("Is Dave there?");
Serial.println("<=== Creamery Status Update ===>");
Serial.print("Selector: ");
Serial.println(selector);
Serial.print("Interval: ");
Serial.println(interval);
Serial.print("Primary Color: ");
Serial.println(primary);
Serial.print("Frequency: ");
Serial.println(frequency);
Serial.print("Density: ");
Serial.println(density);
Serial.print("Decay: ");
Serial.println(decay);
Serial.print("Phase: ");
Serial.println(phase);
Serial.print("DEBUG: ");
Serial.println(DEBUG);
Serial.print("VERBOSE: ");
Serial.println(verbose);
Serial.println("<===========>");
Serial.println("");
/// checking how many items are in the menu / effect list.
// for (int j=0;j<menu_count;j++) {
// Serial.println(j);
// }
// resetMessageBuffer();
}
/* Helper functions */
void updatePrimary(uint32_t c) {primary = c;}
void updateSecondary(uint32_t c) {secondary = c;}
void updateTertiary(uint32_t c) {tertiary = c;}
// Update a specific flavor.
void updateFlavor(uint8_t flavor, uint32_t c) {
switch (flavor) {
case 1:
primary = c;
// do something
break;
case 2:
secondary = c;
// do something
break;
case 3:
tertiary = c;
// do something
break;
default:
primary = c;
// do something
}
}
// Update all flavors randomly.
void updateAssorted() {
primary = RandomWheel();
secondary = RandomWheel();
tertiary = RandomWheel();
}
//Shorter random function, static helper.
uint8_t R(uint8_t from, uint8_t to){ return TrueRandom.random(from, to); }
uint32_t RandomColor(){ return color(TrueRandom.random(0,255), TrueRandom.random(0,255), TrueRandom.random(0,255)); }
uint32_t RandomWheel() { return Wheel(TrueRandom.random(0,255)%255); }
uint32_t rgba(byte r, byte g, byte b, double a) {
int rr = r*a;
int gg = g*a;
int bb = b*a;
return color(rr,gg,bb);
}
// Create a 24 bit color value from R,G,B
uint32_t color(byte r, byte g, byte b, double a) {
int rr = r*a;
int gg = g*a;
int bb = b*a;
return color(rr,gg,bb);
}
// Create a 24 bit color value from R,G,B
uint32_t color(byte r, byte g, byte b) {
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;
return c;
}
uint32_t color(uint32_t c, double a) {
uint8_t r = extractRed(c);
uint8_t g = extractGreen(c);
uint8_t b = extractBlue(c);
return rgba(r,g,b,a);
}
uint32_t alpha(uint32_t c, double a) {
uint8_t r = extractRed(c);
uint8_t g = extractGreen(c);
uint8_t b = extractBlue(c);
return rgba(r,g,b,a);
}
// Helpers to extract RGB from 32bit color. (/// This could be MACRO...)
uint8_t extractRed(uint32_t c) { return (( c >> 16 ) & 0xFF); }
uint8_t extractGreen(uint32_t c) { return ( (c >> 8) & 0xFF ); }
uint8_t extractBlue(uint32_t c) { return ( c & 0xFF ); }
//Input a value 0 to 255 to get a color value.
//The colours are a transition r - g -b - back to r
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
// This is Wheel with alpha.
uint32_t Wheel(byte WheelPos, double alpha) {
if (WheelPos < 85) {
return rgba(WheelPos * 3, 255 - WheelPos * 3, 0,alpha);
} else if (WheelPos < 170) {
WheelPos -= 85;
return rgba(255 - WheelPos * 3, 0, WheelPos * 3,alpha);
} else {
WheelPos -= 170;
return rgba(0, WheelPos * 3, 255 - WheelPos * 3,alpha);
}
}
//
//
// void singlePulseWipe(uint32_t c, uint16_t dir, uint16_t f, uint16_t wait) {
// int i;
//
// for(i=0; i<strip.numPixels();i++)
// {
// singlePulse(i,c,f,wait);
// }
//
// }
//
// // We need an effect that hits just one panel
// // Pixel, Color, Freq, Sust
// void singlePulse(uint8_t n,uint32_t c, uint16_t f, uint16_t wait) {
// // Make sure if you are trying to hit a whole panel, you set the orientation and mode of grid.
//
// int i;
// double alpha;
//
// for(alpha=0;alpha<1;alpha=alpha+0.01) {
// q(n, Color(c,alpha));
// strip.show();
// delay(wait);
// }
// // strip.show();
//
// delay(f);
//
// // FadeOut(wait);
//
// }
//
// //Nuff said, only duration, not speed can be set (made this 15 minutes before you took my balls.)
// void strobe(uint8_t runs){
// int i;
// int r;
// int total = strip.numPixels();
// for(r=0;r<runs;r++) {
// for(i=0;i<total;i++){
// q(i, rgba(255,255,255,0.2));
// }
// strip.show();
// delay(25);
//
// for(i=0;i<total;i++){
// q(i, Color(0,0,0));
// }
// strip.show();
// delay(100);
// }
// }
//
// // Butterfly Effect
// void ButterflyEffect() {
// int i;
// for (i=1;i<255;i++) {
// Sparkle(Color(0,0,0), 1, 10, 50, Wheel(i));
// }
// }
//
// // Malfunction-like effect with blanks and color;
// void Malfunction() {
// int i;
// for (i=1;i<255;i++) {
// if (i%2) {
// Sparkle(Color(0,0,0), 10, 10, 100, Wheel(i));
// } else {
// Sparkle(RandomWheel(), 10, 10, 10, Wheel(i));
// }
// }
// }
//
//
// void PolkadotCycle(uint32_t c, uint32_t d, uint32_t wait) {
//
// for (int j=0; j < 256 * 5; j++) { // 5 cycles of all 25 colors in the wheel
// for (int i=0; i < strip.numPixels(); i++) {
//
// if ((i%2)==0) {
// q(i, c);
// } else {
// q(i, d);
// }
// }
//
// // q(i, Wheel( ((i * 256 / strip.numPixels()) + j) % 256) );
// }
// strip.show(); // write all the pixels out
// delay(wait);
//
// }
//
// // Usage:
// // polkadots(Color(255,0,255),Color(0,255,255), 50);
// void polkadotFill(uint32_t c, uint32_t d, uint32_t wait) {
// int i;
//
// for (i=0; i < strip.numPixels(); i++) {
//
// if ((i%2)==0) {
// q(i, c);
// } else {
// q(i, d);
// }
// }
// strip.show();
// delay(wait);
// }
//
// void PolkadotPulse(uint32_t c, uint32_t d, uint32_t wait, uint8_t sustain) {
//
// int i;
// double alpha;
// int total = strip.numPixels();
//
// for(alpha=0;alpha<1;alpha=alpha+0.01) {
// for(i=0;i<total;i++) {
// if ((i%2)==0) {
// q(i, Color(c,alpha));
// } else {
// q(i, Color(d,alpha));
// }
// }
// strip.show();
// delay(wait);
// }
// // strip.show();
//
// delay(sustain);
// FadeOut(wait);
// // for(alpha=1;alpha>0;alpha=alpha-0.01) {
// // if ((i%2)==0) {
// // q(i, Color(c,alpha));
// // } else {
// // q(i, Color(d,alpha));
// // }
// // strip.show();
// // delay(wait);
// // }
// // strip.show();
//
// }
//
// //Builds up a white sparkle, and then does a random sparkle for colors.
// void SparkleChaos1(){
// int go = 0;
// int density = 1;
// for(go=0;go<255;go++) {
// if(go>50) { density = 2; }
// else if(go>100) {density = 3; }
// else if(go>150) {density = 4; }
// else if(go > 200) {density = 5; }
// else if(go > 225) { density = 7; }
// Sparkle(Color(go,go,go), density, 0);
// delay(10);
// }
// for(go=0;go<100;go++) { SparkleRandom(); }
//
// FadeOut(10);
// }
//
// /// /Builds a sparkle faster and then slows it down./
// // void FasterSlower(){
// // SparkleFaster(500);
// // SparkleSlower(500);
// // }
//
// void RainbowPulse(uint32_t wait) {
//
// int i;
// for(i=0;i<255;i+=23) {
// ColorPulse(Wheel(i),wait);
// }
// }
//
// void ColorPulse(uint32_t color,uint32_t wait) {
// FadeInAll(color, wait);
// FadeOutAll(color, wait);
// // delay(wait);
// }
//
// //
// // THIS STUFF IS USEFUL!!!!!
// //
//
// void FadeInOutWhite(uint32_t wait){
// FadeInAll(Color(255,255,255), wait);
// FadeOutAll(Color(255,255,255), wait);
// }
//
// void FadeInOutRandom(uint32_t wait){
// uint32_t color = RandomColor();
// FadeInAll(color, wait);
// FadeOutAll(color, wait);
// }
//
// void FadeInAll(uint32_t color, uint32_t wait){
// int i;
// double alpha;
// int total = strip.numPixels();
//
// for(alpha=0;alpha<1;alpha=alpha+0.01) {
// for(i=0;i<total;i++) {
// q(i, Color(color,alpha));
// }
// strip.show();
// delay(wait);
// }
// strip.show();
// }
//
// void FadeOutAll(uint32_t color, uint32_t wait){
// int i;
// double alpha;
// int total = strip.numPixels();
//
// for(alpha=1;alpha>0;alpha=alpha-0.01) {
// for(i=0;i<total;i++) {
// q(i,Color(color,alpha));
// }
// strip.show();
// delay(wait);
// }
// strip.show();
// }
//
// void FadeInSparkles(uint32_t color, uint32_t wait){
// int i;
// double alpha;
// int total = strip.numPixels();
//
// for(alpha=0;alpha<0.25;alpha=alpha+0.01) {
// for(i=0;i<total;i++) {
// Sparkle(Wheel(color,alpha), TrueRandom.random(1,25), 25);
// }
// strip.show();
// delay(wait);
// }
// strip.show();
// }
//
// void FadeOutSparkles(uint8_t r, uint8_t g, uint8_t b, uint32_t wait){
// int i;
// double alpha;
// int total = strip.numPixels();
//
// for(alpha=0.25;alpha>0;alpha=alpha-0.01) {
// for(i=0;i<total;i++) {
// Sparkle(rgba(r,g,b,alpha), TrueRandom.random(1,25), 25);
// }
// strip.show();
// delay(wait);
// }
// strip.show();
// }
//
// //This is the exact same thing as Sparkle except with random colors.
//
// void SparkleRainbow(uint8_t density, uint32_t wait){
// int total=strip.numPixels();
// int r;
// int i;
// int pixel;
//
// //Set all pixels to bg
// for(i=0; i < strip.numPixels(); i++ ) {
// //Set color
// q(i, Color(0,0,0));
// }