-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimatedLEDStrip.cpp
More file actions
951 lines (578 loc) · 35.5 KB
/
AnimatedLEDStrip.cpp
File metadata and controls
951 lines (578 loc) · 35.5 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
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
#include "AnimatedLEDStrip.h"
/** Method to run an Alternate animation
@param colorValues1 The first color to be displayed
@param colorValues2 The second color to be displayed
@param delayTime The time (in milliseconds) that each color is displayed for */
void AnimatedLEDStrip::alternate(ColorContainer colorValues1, ColorContainer colorValues2, int delayTime) {
setStripColor(colorValues1); // Set strip to colorValues1
delay(delayTime); // Delay for delayTime milliseconds
setStripColor(colorValues2); // Set strip to colorValues2
delay(delayTime); // Delay for delayTime milliseconds
return; // Return
}
/** Overloaded method to run an Alternate animation
@param r1In The red intensity for the first color
@param g1In The green intensity for the first color
@param b1In The blue intensity for the first color
@param r2In The red intensity for the second color
@param g2In The green intensity for the second color
@param b2In The blue intensity for the second color
@param delayTime The time (in milliseconds) that each color is displayed for */
void AnimatedLEDStrip::alternate(int r1In, int g1In, int b1In, int r2In, int g2In, int b2In, int delayTime) {
ColorContainer temp1 = ColorContainer(r1In, g1In, b1In); // Create temporary ColorContainer for colorValues1
ColorContainer temp2 = ColorContainer(r2In, g2In, b2In); // Create temporary ColorContainer for colorValues2
alternate(temp1, temp2, delayTime); // Call main alternate method
return; // Return
}
/** Method to fade a pixel's red value from one intensity to another
@param pixel The pixel that will be changed
@param startIntensity The intensity that the pixel will begin at
@param endIntensity The intensity that the pixel will end at
@param revertAtCompletion Specifies if the pixel should revert to the color it had prior to the animation (default false) */
void AnimatedLEDStrip::fadePixelRed(int pixel, int startIntensity, int endIntensity, bool revertAtCompletion = false) {
fadeDirection fade; // Initialize fade variable that will specify the direction the fade needs to go
if (startIntensity > endIntensity)
fade = fadeDown; // If the end intensity is lower than the start intensity, the function needs to fade down
if (startIntensity < endIntensity)
fade = fadeUp; // If the end intensity is higher than the start intensity, the function needs to fade up
if (startIntensity == endIntensity)
return; // If the start and end intensities are equal, the function has no work to do
ColorContainer originalValues = getPixelColor(
pixel); // Save original color of the pixel so that the pixel can be reverted at the end if desired
switch (fade) { // Switching on the fade variable
case fadeUp: // If set to fadeUp:
for (int i = startIntensity; i <=
endIntensity; i++) { // Run through each intensity from the start intensity to the end intensity...
setPixelRed(pixel, i); // ...Setting the pixel's red intensity...
show(); // ...And updating the pixel after each change
}
break;
case fadeDown: // If set to fadeDown:
for (int i = startIntensity; i >=
endIntensity; i--) { // Run through each intensity from the start intensity to the end intensity...
setPixelRed(pixel, i); // ...Setting the pixel's red intensity...
show(); // ...And updating the pixel after each change
}
break;
}
if (revertAtCompletion)
setPixelColor(pixel,
originalValues); // If the user wants the pixel to revert to its original color, revert it here
return; // Return
}
/** Method to fade a pixel's green value from one intensity to another
@param pixel The pixel that will be changed
@param startIntensity The intensity that the pixel will begin at
@param endIntensity The intensity that the pixel will end at
@param revertAtCompletion Specifies if the pixel should revert to the color it had prior to the animation (default false) */
void
AnimatedLEDStrip::fadePixelGreen(int pixel, int startIntensity, int endIntensity, bool revertAtCompletion = false) {
fadeDirection fade; // Initialize the fade variable that will specify the direction the fade needs to go
if (startIntensity > endIntensity)
fade = fadeDown; // If the end intensity is lower than the start intensity, the function needs to fade down
if (startIntensity < endIntensity)
fade = fadeUp; // If the end intensity is higher than the start intensity, the function needs to fade up
if (startIntensity == endIntensity)
return; // If the start and end intensities are equal, the function has no work to do
ColorContainer originalValues = getPixelColor(
pixel); // Save original color of the pixel so that the pixel can be reverted at the end if desired
switch (fade) { // Switching on the fade variable
case fadeUp: // If set to fadeUp:
for (int i = startIntensity; i <=
endIntensity; i++) { // Run through each intensity from the start intensity to the end intensity...
setPixelGreen(pixel,
i); // ...Setting the pixel's green intensity...
show(); // ...And updating the pixel after each change
}
break;
case fadeDown: // If set to fadeDown:
for (int i = startIntensity; i >=
endIntensity; i--) { // Run through each intensity from the start intensity to the end intensity...
setPixelGreen(pixel,
i); // ...Setting the pixel's green intensity...
show(); // ...And updating the pixel after each change
}
break;
}
if (revertAtCompletion)
setPixelColor(pixel,
originalValues); // If the user wants the pixel to revert to its original color, revert it here
return; // Return
}
/** Method to fade a pixel's blue value from one intensity to another
@param pixel The pixel that will be changed
@param startIntensity The intensity that the pixel will begin at
@param endIntensity The intensity that the pixel will end at
@param revertAtCompletion Specifies if the pixel should revert to the color it had prior to the animation (default false) */
void AnimatedLEDStrip::fadePixelBlue(int pixel, int startIntensity, int endIntensity, bool revertAtCompletion = false) {
fadeDirection fade; // Initialize the fade variable that will specify the direction the fade needs to go
if (startIntensity > endIntensity)
fade = fadeDown; // If the end intensity is lower than the start intensity, the function needs to fade down
if (startIntensity < endIntensity)
fade = fadeUp; // If the end intensity is higher than the start intensity, the function needs to fade up
if (startIntensity == endIntensity)
return; // If the start and end intensities are equal, the function has no work to do
ColorContainer originalValues = getPixelColor(
pixel); // Save original color of the pixel so that the pixel can be reverted at the end if desired
switch (fade) { // Switching on the fade variable
case fadeUp: // If set to fadeUp:
for (int i = startIntensity; i <=
endIntensity; i++) { // Run through each intensity from the start intensity to the end intensity...
setPixelBlue(pixel,
i); // ...Setting the pixel's blue intensity...
show(); // ...And updating the pixel after each change
}
break;
case fadeDown: // If set to fadeDown:
for (int i = startIntensity; i >=
endIntensity; i--) { // Run through each intensity from the start intensity to the end intensity...
setPixelBlue(pixel,
i); // ...Setting the pixel's blue intensity...
show(); // ...And updating the pixel after each change
}
break;
}
if (revertAtCompletion)
setPixelColor(pixel,
originalValues); // If the user wants the pixel to revert to its original color, revert it here
return; // Return
}
/** Method to fade a pixel's red, green and blue values from one set of intensities to another
@param pixel The pixel that will be changed
@param startRedIntensity The intensity that the pixel's red value will begin at
@param startGreenIntensity The intensity that the pixel's green value will begin at
@param startBlueIntensity The intensity that the pixel's blue value will begin at
@param endRedIntensity The intensity that the pixel's red value will end at
@param endGreenIntensity The intensity that the pixel's green value will end at
@param endBlueIntensity The intensity that the pixel's blue value will end at
@param revertAtCompletion Specifies if the pixel should revert to the color it had prior to the animation (default false) */
void AnimatedLEDStrip::fadePixelAll(int pixel, int startRedIntensity, int startGreenIntensity, int startBlueIntensity,
int endRedIntensity, int endGreenIntensity, int endBlueIntensity,
bool revertAtCompletion = false) {
ColorContainer originalValues = getPixelColor(
pixel); // Save the original color of the pixel so that the pixel can be reverted at the end if desired
setPixelRed(pixel, startRedIntensity); // Set pixel's red intensity to startRedIntensity
setPixelGreen(pixel,
startGreenIntensity); // Set pixel's green intensity to startGreenIntensity
setPixelBlue(pixel,
startBlueIntensity); // Set pixel's blue intensity to startBlueIntensity
bool redComplete = false; // Initialize redComplete, which will keep track of if the red intensity has reached endRedIntensity
bool greenComplete = false; // Initialize greenComplete, which will keep track of if the green intensity has reached endGreenIntensity
bool blueComplete = false; // Initialize blueComplete, which will keep track of if the blue intensity has reached endBlueIntensity
while (!redComplete || !greenComplete ||
!blueComplete) { // While red, green and/or blue have not reached their final intensity, continue loop
if (!redComplete) { // If redComplete is still false
if (getPixelRed(pixel) <
endRedIntensity) { // If the red intensity is below endRedIntensity
setPixelRed(pixel, getPixelRed(pixel) + 1); // Increase the red intensity
} else if (getPixelRed(pixel) >
endRedIntensity) { // Or if the red intensity is above endRedIntensity
setPixelRed(pixel, getPixelRed(pixel) - 1); // Decrease the red intensity
} else { // Otherwise red must be equal to endRedIntensity
redComplete = true; // So make redComplete true
}
}
if (!greenComplete) { // If greenComplete is still false
if (getPixelGreen(pixel) <
endGreenIntensity) { // If the green intensity is below endGreenIntensity
setPixelGreen(pixel, getPixelGreen(pixel) + 1); // Increase the green intensity
} else if (getPixelGreen(pixel) >
endGreenIntensity) { // Or if the green intensity is above endGreenIntensity
setPixelGreen(pixel, getPixelGreen(pixel) - 1); // Decrease the green intensity
} else { // Otherwise green must be equal to endGreenIntensity
greenComplete = true; // So make greenComplete true
}
}
if (!blueComplete) { // If blueComplete is still false
if (getPixelBlue(pixel) <
endBlueIntensity) { // If the blue intensity is below endBlueIntensity
setPixelBlue(pixel, getPixelBlue(pixel) + 1); // Increase the blue intensity
} else if (getPixelBlue(pixel) >
endRedIntensity) { // Or if the blue intensity is above endBlueIntensity
setPixelBlue(pixel, getPixelBlue(pixel) - 1); // Decrease the blue intensity
} else { // Otherwise blue must be equal to endBlueIntensity
blueComplete = true; // So make blueComplete true
}
}
show(); // Send new color data to pixels
}
if (revertAtCompletion)
setPixelColor(pixel,
originalValues); // If the user wants the pixel to revert to its original color, revert it here
return; // Return
}
/** Method to run a Multi-Pixel Run animation
Calls multiPixelRun(int, direction, ColorContainer) with inputted parameters
@param spacing The number of LEDs until the next LED to be lit is reached
@param chaseDirection Specifies if the animation should run 'forward' or 'backward'
@param colorValues The color of the 'running' pixels
@param altColorValues The color of the remaining pixels */
void AnimatedLEDStrip::multiPixelRun(int spacing, direction chaseDirection, ColorContainer colorValues,
ColorContainer altColorValues = CRGB::Black) {
if (chaseDirection == backward) {
for (int q = 0; q < spacing; q++) {
setStripColor(altColorValues);
for (int i = 0; i < getPixelCount(); i += spacing) {
setPixelColor(i + (-(q - (spacing - 1))), colorValues);
}
show();
delay(50);
for (int i = 0; i < getPixelCount(); i += spacing) {
setPixelColor(i + (-(q - (spacing - 1))), altColorValues);
}
}
}
if (chaseDirection == forward) {
for (int q = spacing - 1; q >= 0; q--) {
setStripColor(altColorValues);
for (int i = 0; i < getPixelCount(); i += spacing) {
setPixelColor(i + (-(q - (spacing - 1))), colorValues);
}
show();
delay(50);
for (int i = 0; i < getPixelCount(); i += spacing) {
setPixelColor(i + (-(q - (spacing - 1))), altColorValues);
}
}
}
return;
}
/** Overloaded method to run a Multi-Pixel Run animation
Calls multiPixelRun(int, direction, ColorContainer) with inputted parameters
@param spacing The number of LEDs until the next LED to be lit is reached
@param chaseDirection Specifies if the animation should run 'forward' or 'backward'
@param rIn1 The red value for the 'running' pixels
@param gIn1 The green value for the 'running' pixels
@param bIn1 The blue value for the 'running' pixels
@param rIn2 The red value for the remaining pixels (default 0)
@param gIn2 The green value for the remaining pixels (default 0)
@param bIn2 The blue value for the remaining pixels (default 0) */
void AnimatedLEDStrip::multiPixelRun(int spacing, direction chaseDirection, int rIn1, int gIn1, int bIn1, int rIn2 = 0,
int gIn2 = 0, int bIn2 = 0) {
ColorContainer temp1(rIn1, gIn1, bIn1); // Create temporary ColorContainer for colorValues
ColorContainer temp2(rIn2, gIn2, bIn2); // Create temporary ColorContainer for altColorValues
multiPixelRun(spacing, chaseDirection, temp1, temp2); // Call main multiPixelRun method
return; // Return
}
/** Method to run a Pixel Run animation
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param colorValues The color of the 'running' pixel
@param altColorValues The color of the remaining pixels */
void AnimatedLEDStrip::pixelRun(direction movementDirection, ColorContainer colorValues,
ColorContainer altColorValues = CRGB::Black) {
setStripColor(altColorValues);
if (movementDirection == forward) {
for (int q = 0; q < getPixelCount(); q++) {
setPixelColor(q, colorValues);
delay(50);
setPixelColor(q, altColorValues);
}
}
if (movementDirection == backward) {
for (int q = getPixelCount() - 1; q >= 0; q--) {
setPixelColor(q, colorValues);
delay(50);
setPixelColor(q, altColorValues);
}
}
return;
}
/** Overloaded method to run a Pixel Run animation
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param r1In The red value for the 'running' pixel
@param g1In The green value for the 'running' pixel
@param b1In The blue value for the 'running' pixel
@param r2In The red value for the remaining pixels (default 0)
@param g2In The green value for the remaining pixels (default 0)
@param b2In The blue value for the remaining pixels (default 0) */
void AnimatedLEDStrip::pixelRun(direction movementDirection, int r1In, int g1In, int b1In, int r2In = 0, int g2In = 0,
int b2In = 0) {
ColorContainer temp1 = ColorContainer(r1In, g1In, b1In);
ColorContainer temp2 = ColorContainer(r2In, g2In, b2In);
pixelRun(movementDirection, temp1, temp2);
return;
}
/** Method to run a Pixel Run with Trail animation
Similar to a Pixel Run animation but the 'running' pixel has a trail behind it
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param colorValues The color of the 'running' pixel
@param altColorValues The color the remaining pixels will fade to */
void AnimatedLEDStrip::pixelRunWithTrail(direction movementDirection, ColorContainer colorValues,
ColorContainer altColorValues = CRGB::Black) {
CRGB altColorCRGB = CRGB(altColorValues.getr(), altColorValues.getg(), altColorValues.getb());
if (movementDirection == forward) {
for (int q = 0; q < getPixelCount(); q++) {
for (int i = 0; i < getPixelCount(); i++) {
setPixelColor(i, blend(CRGB(getPixelColor(i).getr(), getPixelColor(i).getg(), getPixelColor(i).getb()),
altColorCRGB, 60));
}
setPixelColor(q, colorValues);
delay(50);
}
}
if (movementDirection == backward) {
for (int q = getPixelCount() - 1; q >= 0; q--) {
for (int i = 0; i < getPixelCount(); i++) {
setPixelColor(i, blend(CRGB(getPixelColor(i).getr(), getPixelColor(i).getg(), getPixelColor(i).getb()),
altColorCRGB, 60));
}
setPixelColor(q, colorValues);
delay(50);
}
}
return;
}
/** Overloaded method to run a Pixel Run animation
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param r1In The red value for the 'running' pixel
@param g1In The green value for the 'running' pixel
@param b1In The blue value for the 'running' pixel
@param r2In The red value the remaining pixels will fade to (default 0)
@param g2In The green value the remaining pixels will fade to (default 0)
@param b2In The blue value the remaining pixels will fade to (default 0) */
void AnimatedLEDStrip::pixelRunWithTrail(direction movementDirection, int r1In, int g1In, int b1In, int r2In = 0,
int g2In = 0, int b2In = 0) {
ColorContainer temp1 = ColorContainer(r1In, g1In, b1In);
ColorContainer temp2 = ColorContainer(r2In, g2In, b2In);
pixelRunWithTrail(movementDirection, temp1, temp2);
return;
}
/** Method to run a Smooth Chase animation using a RGB color palette that blends the colors to make smooth transitions between them
Main smoothChase method
@param palette The palette to be used (can be CRGBPalette16, CRGBPalette32, CRGBPalette256, CHSVPalette16, CHSVPalette32, CHSVPalette256, TProgmemRGBPalette16, TProgmemRGBPalette32, TProgmemHSVPalette16 or TProgmemHSVPalette32)
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param brightness The brightness of the LEDs (default 255) */
template<class paletteType>
void AnimatedLEDStrip::smoothChase(const paletteType &palette, direction movementDirection, uint8_t brightness) {
if (movementDirection == forward) {
for (uint8_t startIndex = 255; startIndex > 0; startIndex--) { // Run through one cycle
fillLEDsFromPalette(palette, startIndex, LINEARBLEND,
brightness); // Fill in colors from the specified palette
delay(10);
show(); // Send color data to LEDs
}
} else if (movementDirection == backward) {
for (uint8_t startIndex = 0; startIndex < 255; startIndex++) { // Run through one cycle
fillLEDsFromPalette(palette, startIndex, LINEARBLEND,
brightness); // Fill in colors from the specified palette
delay(10);
show(); // Send color data to LEDs
}
}
return; // Return
}
/** Method to run a Smooth Chase animation using a RGB color palette that blends the colors to make smooth transitions between them
Calls smoothChase<TProgmemRGBPalette16>(paletteType, direction, uint8_t) with inputted parameters
@param palette The TProgmemRGBPalette16 palette to be used
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param brightness The brightness of the LEDs (default 255) */
void AnimatedLEDStrip::smoothChase(const TProgmemRGBPalette16 &palette, direction movementDirection,
uint8_t brightness = 255) {
smoothChase<TProgmemRGBPalette16>(palette, movementDirection, brightness); // Call main smoothChase method
return; // Return
}
/** Method to run a Smooth Chase animation using a RGB color palette that blends the colors to make smooth transitions between them
Calls smoothChase<CRGBPalette16>(paletteType, direction, uint8_t) with inputted parameters
@param palette The CRGBPalette16 palette to be used
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param brightness The brightness of the LEDs (default 255) */
void
AnimatedLEDStrip::smoothChase(const CRGBPalette16 &palette, direction movementDirection, uint8_t brightness = 255) {
smoothChase<CRGBPalette16>(palette, movementDirection, brightness); // Call main smoothChase method
return; // Return
}
/** Method to run a Smooth Chase animation using a RGB color palette that blends the colors to make smooth transitions between them
Calls smoothChase<CRGBPalette32>(paletteType, direction, uint8_t) with inputted parameters
@param palette The CRGBPalette32 palette to be used
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param brightness The brightness of the LEDs (default 255) */
void
AnimatedLEDStrip::smoothChase(const CRGBPalette32 &palette, direction movementDirection, uint8_t brightness = 255) {
smoothChase<CRGBPalette32>(palette, movementDirection, brightness); // Call main smoothChase method
return; // Return
}
/** Method to run a Smooth Chase animation using a RGB color palette that blends the colors to make smooth transitions between them
Calls smoothChase<CRGBPalette256>(paletteType, direction, uint8_t) with inputted parameters
@param palette The CRGBPalette256 palette to be used
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param brightness The brightness of the LEDs (default 255) */
void
AnimatedLEDStrip::smoothChase(const CRGBPalette256 &palette, direction movementDirection, uint8_t brightness = 255) {
smoothChase<CRGBPalette256>(palette, movementDirection, brightness); // Call main smoothChase method
return; // Return
}
/** Method to run a Smooth Chase animation using a HSV color palette that blends the colors to make smooth transitions between them
Calls smoothChase<CHSVPalette16>(paletteType, direction, uint8_t) with inputted parameters
@param palette The CHSVPalette16 palette to be used
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param brightness The brightness of the LEDs (default 255) */
void
AnimatedLEDStrip::smoothChase(const CHSVPalette16 &palette, direction movementDirection, uint8_t brightness = 255) {
smoothChase<CHSVPalette16>(palette, movementDirection, brightness); // Call main smoothChase method
return; // Return
}
/** Method to run a Smooth Chase animation using a HSV color palette that blends the colors to make smooth transitions between them
Calls smoothChase<CHSVPalette32>(paletteType, direction, uint8_t) with inputted parameters
@param palette The CHSVPalette32 palette to be used
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param brightness The brightness of the LEDs (default 255) */
void
AnimatedLEDStrip::smoothChase(const CHSVPalette32 &palette, direction movementDirection, uint8_t brightness = 255) {
smoothChase<CHSVPalette32>(palette, movementDirection, brightness); // Call main smoothChase method
return; // Return
}
/** Method to run a Smooth Chase animation using a HSV color palette that blends the colors to make smooth transitions between them
Calls smoothChase<CHSVPalette256>(paletteType, direction, uint8_t) with inputted parameters
@param palette The CHSVPalette256 palette to be used
@param movementDirection Specifies if the animation should run 'forward' or 'backward'
@param brightness The brightness of the LEDs (default 255) */
void
AnimatedLEDStrip::smoothChase(const CHSVPalette256 &palette, direction movementDirection, uint8_t brightness = 255) {
smoothChase<CHSVPalette256>(palette, movementDirection, brightness); // Call main smoothChase method
return; // Return
}
/** Method to run a Sparkle animation
@param sparkleColor The color that LEDs will be set to for a brief moment */
void AnimatedLEDStrip::sparkle(ColorContainer sparkleColor) {
ColorContainer originalColor;
shuffle();
for (int i = 0; i < getPixelCount(); i++) {
originalColor = getPixelColor(shuffleArray[i]);
setPixelColor(shuffleArray[i], sparkleColor);
show();
delay(50);
setPixelColor(shuffleArray[i], originalColor);
}
}
/** Overloaded method to run a sparkle animation
@param rIn The red intensity for the sparkle color
@param gIn The green intensity for the sparkle color
@param bIn The blue intensity for the sparkle color */
void AnimatedLEDStrip::sparkle(int rIn, int gIn, int bIn) {
ColorContainer temp(rIn, gIn, bIn);
sparkle(temp);
return;
}
/** Method to run a Sparkle to Color animation
@param destinationColor The color all pixels will be set to by the end of the animation */
void AnimatedLEDStrip::sparkleToColor(ColorContainer destinationColor) {
shuffle();
for (int i = 0; i < getPixelCount(); i++) {
setPixelColor(shuffleArray[i], destinationColor);
show();
delay(10);
}
}
/** Overloaded method to run a sparkle to color animation
@param rIn The red intensity for the destination color
@param gIn The green intensity for the destination color
@param bIn The blue intensity for the destination color */
void AnimatedLEDStrip::sparkleToColor(int rIn, int gIn, int bIn) {
ColorContainer temp = ColorContainer(rIn, gIn, bIn);
sparkleToColor(temp);
return;
}
/** Method to run a Wipe animation
Changes the strip to the specified color, but one pixel at a time. Looks and works similar to a Pixel Run animation.
@param colorValues The color that the strip will be at the end of the animation
@param wipeDirection Specifies if the animation should run 'forward' or 'backward' */
void AnimatedLEDStrip::wipe(ColorContainer colorValues, direction wipeDirection) {
if (wipeDirection == backward) {
for (int i = getPixelCount() - 1; i >= 0; i--) { // Run through the length of the strip
setPixelColor(i, colorValues); // Set pixel color to colorValues
show(); // Send color data to LEDs
delay(10);
}
}
if (wipeDirection == forward) {
for (int i = 0; i < getPixelCount(); i++) { // Run through the length of the strip
setPixelColor(i, colorValues); // Set pixel color to colorValues
show(); // Sendc color data to LEDs
delay(10);
}
}
}
/** Overloaded method to run a wipe animation
@param rIn The red intensity for the destination color
@param gIn The green intensity for the destination color
@param bIn The blue intensity for the destination color
@param wipeDirection Specifies if the animation should run 'forward' or 'backward' */
void AnimatedLEDStrip::wipe(int rIn, int gIn, int bIn, direction wipeDirection) {
ColorContainer temp = ColorContainer(rIn, gIn, bIn);
wipe(temp, wipeDirection);
return;
}
void AnimatedLEDStrip::stack(direction stackDirection, ColorContainer colorValues, ColorContainer altColorValues = CRGB::Black) {
setStripColor(altColorValues);
if (stackDirection == forward) {
for (int q = getPixelCount() - 1; q >= 0; q--) {
for (int i = 0; i < q; i++) {
setPixelColor(i, colorValues);
show();
delay(10);
setPixelColor(i, altColorValues);
}
setPixelColor(q, colorValues);
show();
}
}
if (stackDirection == backward) {
for (int q = 0; q < getPixelCount(); q++) {
for (int i = getPixelCount() - 1; i > q; i--) {
setPixelColor(i, colorValues);
show();
delay(10);
setPixelColor(i, altColorValues);
}
setPixelColor(q, colorValues);
show();
}
}
return;
}
/** @deprecated Use multiPixelRun( int spacing, direction chaseDirection, ColorContainer colorValues) instead
Method to run a chase animation
@param spacing The number of LEDs until the next LED to be lit is reached
@param chaseDirection Specifies if the animation should run 'forward' or 'backward'
@param colorValues A ColorContainer containing the desired color */
void AnimatedLEDStrip::chase(int spacing, direction chaseDirection, ColorContainer colorValues) {
ColorContainer Black;
if (chaseDirection == forward) {
for (int q = 0; q < spacing; q++) {
for (int i = 0; i < getPixelCount(); i += spacing) {
setPixelColor(i + (-(q - (spacing - 1))), colorValues);
}
show();
delay(50);
for (int i = 0; i < getPixelCount(); i += spacing) {
setPixelColor(i + (-(q - (spacing - 1))), Black);
}
}
}
if (chaseDirection == backward) {
for (int q = spacing - 1; q >= 0; q--) {
for (int i = 0; i < getPixelCount(); i += spacing) {
setPixelColor(i + (-(q - (spacing - 1))), colorValues);
}
show();
delay(50);
for (int i = 0; i < getPixelCount(); i += spacing) {
setPixelColor(i + (-(q - (spacing - 1))), Black);
}
}
}
return;
}
/** @deprecated Use multiPixelRun( int spacing, direction chaseDirection, int rIn, int gIn, int bIn) instead
Method to run a chase animation
Calls chase(int, direction, ColorContainer) with inputted parameters
@param spacing The number of LEDs until the next LED to be lit is reached
@param chaseDirection Specifies if the animation should run 'forward' or 'backward'
@param rIn The value for the red LED
@param gIn The value for the green LED
@param bIn The value for the blue LED */
void AnimatedLEDStrip::chase(int spacing, direction chaseDirection, int rIn, int gIn, int bIn) {
ColorContainer temp(rIn, gIn, bIn);
chase(spacing, chaseDirection, temp);
return;
}