-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfibonacci-v3d.ino
1477 lines (1191 loc) · 38.4 KB
/
fibonacci-v3d.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
/*
Fibonacci v3D: https://github.com/evilgeniuslabs/fibonacci-v3d
Copyright (C) 2014-2016 Jason Coon, Evil Genius Labs
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <FastLED.h>
#include <IRremote.h>
#include <EEPROM.h>
#define IR_RECV_PIN 12
IRrecv irReceiver(IR_RECV_PIN);
#include "Commands.h"
#include "GradientPalettes.h"
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
#define DATA_PIN 0
// #define COLOR_ORDER RGB
#define LED_TYPE WS2811
#define NUM_LEDS 100
CRGB leds[NUM_LEDS];
const uint8_t brightnessCount = 5;
uint8_t brightnessMap[brightnessCount] = { 16, 32, 64, 128, 255 };
uint8_t brightness = brightnessMap[0];
int patternIndex = 0;
CRGB solidColor = CRGB::Red;
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
int autoPlayDurationSeconds = 10;
unsigned int autoPlayTimout = 0;
bool autoplayEnabled = false;
InputCommand command;
CRGBPalette16 IceColors_p = CRGBPalette16(CRGB::Black, CRGB::Blue, CRGB::Aqua, CRGB::White);
uint8_t paletteIndex = 0;
// List of palettes to cycle through.
CRGBPalette16 palettes[] =
{
RainbowColors_p,
RainbowStripeColors_p,
CloudColors_p,
OceanColors_p,
ForestColors_p,
HeatColors_p,
LavaColors_p,
PartyColors_p,
IceColors_p,
};
uint8_t paletteCount = ARRAY_SIZE(palettes);
CRGBPalette16 currentPalette(CRGB::Black);
CRGBPalette16 targetPalette = palettes[paletteIndex];
// ten seconds per color palette makes a good demo
// 20-120 is better for deployment
#define SECONDS_PER_PALETTE 10
///////////////////////////////////////////////////////////////////////
// Forward declarations of an array of cpt-city gradient palettes, and
// a count of how many there are. The actual color palette definitions
// are at the bottom of this file.
extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
extern const uint8_t gGradientPaletteCount;
// Current palette number from the 'playlist' of color palettes
uint8_t gCurrentPaletteNumber = 0;
CRGBPalette16 gCurrentPalette( CRGB::Black);
CRGBPalette16 gTargetPalette( gGradientPalettes[0] );
uint8_t fibonacciToPhysicalOrder[100] = {
99, 97, 98, 96, 92, 95, 91, 93, 89, 84,
94, 90, 85, 88, 83, 86, 81, 76, 87, 82,
77, 80, 75, 78, 73, 68, 79, 74, 69, 72,
67, 70, 65, 60, 71, 66, 61, 64, 59, 62,
57, 52, 63, 58, 53, 56, 51, 54, 48, 41,
55, 50, 43, 47, 40, 45, 49, 42, 46, 39,
44, 36, 28, 33, 38, 30, 35, 27, 32, 37,
29, 34, 26, 31, 23, 15, 20, 25, 17, 22,
14, 19, 24, 16, 21, 13, 18, 10, 2, 7,
12, 4, 9, 1, 6, 11, 3, 8, 0, 5
};
uint8_t physicalToFibonacciOrder[100] = {
98, 93, 88, 96, 91, 99, 94, 89, 97, 92,
87, 95, 90, 85, 80, 75, 83, 78, 86, 81,
76, 84, 79, 74, 82, 77, 72, 67, 62, 70,
65, 73, 68, 63, 71, 66, 61, 69, 64, 59,
54, 49, 57, 52, 60, 55, 58, 53, 48, 56,
51, 46, 41, 44, 47, 50, 45, 40, 43, 38,
33, 36, 39, 42, 37, 32, 35, 30, 25, 28,
31, 34, 29, 24, 27, 22, 17, 20, 23, 26,
21, 16, 19, 14, 9, 12, 15, 18, 13, 8,
11, 6, 4, 7, 10, 5, 3, 1, 2, 0
};
// Params for width and height
const uint8_t kMatrixWidth = 32;
const uint8_t kMatrixHeight = 32;
const uint8_t maxX = kMatrixWidth - 1;
const uint8_t maxY = kMatrixHeight - 1;
const uint8_t coordsX10[NUM_LEDS] = { 5, 4, 5, 5, 4, 5, 4, 4, 6, 3, 5, 5, 3, 6, 4, 4, 6, 3, 6, 4, 3, 7, 3, 5, 6, 2, 7, 4, 4, 7, 2, 6, 5, 2, 7, 3, 5, 6, 2, 7, 4, 3, 7, 2, 6, 6, 2, 8, 3, 4, 7, 1, 7, 5, 2, 8, 2, 5, 6, 1, 8, 3, 3, 8, 1, 6, 5, 1, 8, 2, 4, 7, 1, 7, 4, 2, 8, 1, 6, 6, 1, 8, 3, 3, 8, 0, 7, 5, 1, 9, 1, 5, 7, 0, 8, 3, 2, 9, 0, 6 };
const uint8_t coordsY10[NUM_LEDS] = { 5, 4, 5, 4, 5, 5, 3, 6, 4, 4, 6, 3, 5, 5, 3, 6, 3, 4, 6, 2, 6, 4, 3, 7, 3, 5, 5, 2, 7, 3, 4, 7, 2, 6, 5, 3, 7, 2, 5, 6, 2, 7, 4, 3, 7, 2, 6, 5, 2, 8, 3, 4, 7, 1, 7, 4, 2, 8, 2, 5, 6, 1, 8, 3, 3, 8, 1, 7, 5, 2, 8, 2, 5, 7, 1, 8, 4, 2, 8, 1, 6, 6, 1, 8, 2, 4, 8, 0, 7, 5, 1, 9, 1, 5, 7, 0, 8, 3, 3, 9 };
const uint8_t coordsX32[NUM_LEDS] = { 17, 15, 16, 18, 13, 19, 15, 14, 20, 11, 18, 18, 11, 22, 12, 15, 21, 9, 21, 16, 11, 23, 10, 18, 20, 8, 24, 13, 13, 24, 7, 21, 18, 9, 25, 9, 16, 23, 6, 24, 14, 10, 26, 6, 20, 20, 6, 27, 10, 14, 25, 4, 24, 16, 8, 28, 7, 18, 23, 4, 27, 12, 11, 28, 4, 22, 19, 5, 29, 8, 15, 26, 2, 26, 15, 8, 30, 4, 20, 23, 2, 30, 10, 12, 29, 1, 25, 18, 4, 31, 5, 17, 26, 0, 29, 12, 8, 31, 1, 22 };
const uint8_t coordsY32[NUM_LEDS] = { 16, 15, 19, 14, 17, 18, 12, 20, 14, 14, 21, 11, 19, 17, 11, 22, 12, 16, 21, 9, 22, 15, 12, 24, 9, 18, 20, 8, 24, 12, 14, 24, 7, 22, 17, 9, 26, 9, 17, 22, 6, 25, 13, 11, 26, 6, 21, 19, 6, 27, 9, 15, 25, 4, 25, 15, 8, 28, 6, 19, 22, 4, 28, 11, 12, 28, 3, 23, 18, 5, 30, 7, 16, 25, 2, 27, 13, 8, 30, 3, 21, 21, 3, 30, 8, 13, 28, 1, 26, 16, 5, 31, 4, 18, 25, 1, 30, 11, 9, 31 };
const uint8_t coordsX[NUM_LEDS] = { 137, 116, 130, 143, 101, 154, 119, 112, 164, 91, 146, 141, 88, 175, 100, 121, 168, 74, 168, 125, 90, 188, 77, 142, 160, 66, 189, 102, 105, 190, 59, 167, 141, 69, 204, 75, 128, 181, 48, 193, 113, 83, 210, 52, 158, 161, 48, 213, 82, 109, 203, 36, 189, 131, 61, 225, 53, 142, 184, 30, 216, 97, 85, 223, 30, 177, 154, 39, 234, 61, 120, 208, 17, 211, 117, 60, 240, 31, 159, 180, 19, 237, 77, 94, 231, 11, 198, 142, 35, 251, 40, 135, 207, 4, 232, 99, 66, 250, 11, 179 };
const uint8_t coordsY[NUM_LEDS] = { 128, 117, 148, 109, 133, 144, 96, 160, 115, 113, 166, 86, 151, 138, 88, 179, 94, 126, 167, 71, 173, 120, 93, 189, 72, 148, 156, 65, 193, 95, 110, 189, 55, 174, 134, 71, 206, 69, 135, 177, 47, 199, 106, 89, 209, 47, 166, 154, 50, 217, 75, 116, 200, 33, 196, 123, 66, 225, 46, 150, 178, 31, 221, 88, 93, 221, 26, 186, 146, 43, 237, 53, 129, 202, 17, 218, 107, 68, 239, 25, 169, 172, 22, 242, 67, 103, 226, 7, 208, 132, 42, 252, 31, 146, 199, 5, 239, 88, 75, 247 };
const uint8_t ledAngles[NUM_LEDS] = { 0, 158, 60, 219, 121, 23, 181, 84, 242, 144, 46, 204, 107, 9, 167, 69, 227, 130, 32, 190, 92, 251, 153, 55, 213, 115, 18, 176, 78, 236, 139, 41, 199, 101, 3, 162, 64, 222, 124, 26, 185, 87, 245, 147, 50, 208, 110, 12, 170, 73, 231, 133, 35, 193, 96, 254, 156, 58, 217, 119, 21, 179, 81, 240, 142, 44, 202, 105, 7, 165, 67, 225, 128, 30, 188, 90, 248, 151, 53, 211, 113, 16, 174, 76, 234, 136, 39, 197, 99, 1, 160, 62, 220, 122, 24, 183, 85, 243, 145, 47 };
const uint8_t ledRadii[NUM_LEDS] = { 0, 3, 5, 8, 10, 13, 15, 18, 20, 23, 26, 28, 31, 33, 36, 38, 41, 44, 46, 49, 51, 54, 56, 59, 61, 64, 67, 69, 72, 74, 77, 79, 82, 84, 87, 90, 92, 95, 97, 100, 102, 105, 108, 110, 113, 115, 118, 120, 123, 125, 128, 131, 133, 136, 138, 141, 143, 146, 148, 151, 154, 156, 159, 161, 164, 166, 169, 172, 174, 177, 179, 182, 184, 187, 189, 192, 195, 197, 200, 202, 205, 207, 210, 212, 215, 218, 220, 223, 225, 228, 230, 233, 236, 238, 241, 243, 246, 248, 251, 253 };
void setPixelA(uint8_t angle, uint8_t dAngle, CRGB color)
{
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t o = physicalToFibonacciOrder[i];
uint8_t ao = ledAngles[o];
if (ao <= qadd8(angle, dAngle) && ao >= qsub8(angle, dAngle)) {
leds[i] = color;
}
}
}
void setPixelAR(uint8_t angle, uint8_t radius, uint8_t dAngle, uint8_t dRadius, CRGB color)
{
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t o = physicalToFibonacciOrder[i];
uint8_t ao = ledAngles[o];
if (ao <= qadd8(angle, dAngle) && ao >= qsub8(angle, dAngle)) {
uint8_t ro = ledRadii[o];
if (ro <= qadd8(radius, dRadius) && ro >= qsub8(radius, dRadius)) {
leds[i] = color;
}
}
}
}
void setPixelXY10(uint8_t x, uint8_t y, CRGB color)
{
if ((x >= 10) || (y >= 10)) {
return;
}
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t o = physicalToFibonacciOrder[i];
if (coordsX10[o] == x && coordsY10[o] == y) {
leds[i] = color;
}
}
}
void setPixelXY(uint8_t x, uint8_t y, CRGB color)
{
if ((x >= kMatrixWidth) || (y >= kMatrixHeight)) {
return;
}
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t o = physicalToFibonacciOrder[i];
if (coordsX32[o] == x && coordsY32[o] == y) {
leds[i] = color;
return;
}
}
}
void powerOff()
{
// clear the display
// fill_solid(leds, NUM_LEDS, CRGB::Black);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Black;
FastLED.show(); // display this frame
delay(1);
}
FastLED.show(); // display this frame
while (true) {
InputCommand command = readCommand();
if (command == InputCommand::Power ||
command == InputCommand::Brightness)
return;
// go idle for a while, converve power
delay(250);
}
}
int getBrightnessLevel() {
int level = 0;
for (int i = 0; i < brightnessCount; i++) {
if (brightnessMap[i] >= brightness) {
level = i;
break;
}
}
return level;
}
void adjustBrightness(int delta) {
int level = getBrightnessLevel();
level += delta;
if (level < 0)
level = brightnessCount - 1;
if (level >= brightnessCount)
level = 0;
brightness = brightnessMap[level];
FastLED.setBrightness(brightness);
EEPROM.write(0, brightness);
}
uint8_t cycleBrightness() {
adjustBrightness(1);
if (brightness == brightnessMap[0])
return 8;
return brightness;
}
// algorithm from http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
void drawCircle(uint8_t x0, uint8_t y0, uint8_t radius, const CRGB color)
{
int a = radius, b = 0;
int radiusError = 1 - a;
if (radius == 0) {
setPixelXY(x0, y0, color);
return;
}
while (a >= b)
{
setPixelXY(a + x0, b + y0, color);
setPixelXY(b + x0, a + y0, color);
setPixelXY(-a + x0, b + y0, color);
setPixelXY(-b + x0, a + y0, color);
setPixelXY(-a + x0, -b + y0, color);
setPixelXY(-b + x0, -a + y0, color);
setPixelXY(a + x0, -b + y0, color);
setPixelXY(b + x0, -a + y0, color);
b++;
if (radiusError < 0)
radiusError += 2 * b + 1;
else
{
a--;
radiusError += 2 * (b - a + 1);
}
}
}
// scale the brightness of all pixels down
void dimAll(byte value)
{
for (int i = 0; i < NUM_LEDS; i++) {
leds[i].nscale8(value);
}
}
// Patterns from FastLED example DemoReel100: https://github.com/FastLED/FastLED/blob/master/examples/DemoReel100/DemoReel100.ino
uint8_t rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 255 / NUM_LEDS);
return 8;
}
void addGlitter( uint8_t chanceOfGlitter)
{
if ( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}
uint8_t rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
return 8;
}
uint8_t rainbowSolid()
{
fill_solid(leds, NUM_LEDS, CHSV(gHue, 255, 255));
return 8;
}
uint8_t confetti()
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
return 8;
}
uint8_t sinelon1()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16(13, 0, NUM_LEDS);
leds[fibonacciToPhysicalOrder[pos]] += CHSV( gHue, 255, 192);
return 8;
}
uint8_t sinelon2()
{
// 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);
return 8;
}
uint8_t bpm1()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for ( int i = 0; i < NUM_LEDS; i++) { //9948
leds[fibonacciToPhysicalOrder[i]] = ColorFromPalette(currentPalette, gHue + (i * 2), beat - gHue + (i * 10));
}
return 8;
}
uint8_t bpm2()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for ( int i = 0; i < NUM_LEDS; i++) { //9948
leds[i] = ColorFromPalette(currentPalette, gHue + (i * 2), beat - gHue + (i * 10));
}
return 8;
}
uint8_t juggle() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
uint8_t dotcount = 3;
for ( int i = 0; i < dotcount; i++) {
leds[beatsin16(i + (dotcount - 1), 0, NUM_LEDS)] |= CHSV(dothue, 200, 255);
dothue += (256 / dotcount);
}
return 8;
}
uint8_t juggle2()
{
static uint8_t numdots = 4; // Number of dots in use.
static uint8_t faderate = 2; // How long should the trails be. Very low value = longer trails.
static uint8_t hueinc = 255 / numdots - 1; // Incremental change in hue between each dot.
static uint8_t thishue = 0; // Starting hue.
static uint8_t curhue = 0; // The current hue
static uint8_t thissat = 255; // Saturation of the colour.
static uint8_t thisbright = 255; // How bright should the LED/display be.
static uint8_t basebeat = 5; // Higher = faster movement.
static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our 'debounce' variable.
uint8_t secondHand = (millis() / 1000) % 30; // IMPORTANT!!! Change '30' to a different value to change duration of the loop.
if (lastSecond != secondHand) { // Debounce to make sure we're not repeating an assignment.
lastSecond = secondHand;
switch (secondHand) {
case 0: numdots = 1; basebeat = 20; hueinc = 16; faderate = 2; thishue = 0; break; // You can change values here, one at a time , or altogether.
case 10: numdots = 4; basebeat = 10; hueinc = 16; faderate = 8; thishue = 128; break;
case 20: numdots = 8; basebeat = 3; hueinc = 0; faderate = 8; thishue = random8(); break; // Only gets called once, and not continuously for the next several seconds. Therefore, no rainbows.
case 30: break;
}
}
// Several colored dots, weaving in and out of sync with each other
curhue = thishue; // Reset the hue values.
fadeToBlackBy(leds, NUM_LEDS, faderate);
for ( int i = 0; i < numdots; i++) {
//beat16 is a FastLED 3.1 function
leds[beatsin16(basebeat + i + numdots, 0, NUM_LEDS)] += CHSV(gHue + curhue, thissat, thisbright);
curhue += hueinc;
}
return 8;
}
// based on FastLED example Fire2012WithPalette: https://github.com/FastLED/FastLED/blob/master/examples/Fire2012WithPalette/Fire2012WithPalette.ino
void heatMap(CRGBPalette16 palette, bool up)
{
fill_solid(leds, NUM_LEDS, CRGB::Black);
// Add entropy to random number generator; we use a lot of it.
random16_add_entropy(random(256));
// COOLING: How much does the air cool as it rises?
// Less cooling = taller flames. More cooling = shorter flames.
// Default 55, suggested range 20-100
uint8_t cooling = 55;
// SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire. Lower chance = more flickery fire.
// Default 120, suggested range 50-200.
uint8_t sparking = 120;
// Array of temperature readings at each simulation cell
static byte heat[kMatrixWidth + 3][kMatrixHeight + 3];
for (int x = 0; x < 10; x++)
{
// Step 1. Cool down every cell a little
for (int y = 0; y < 10; y++)
{
heat[x][y] = qsub8(heat[x][y], random8(0, ((cooling * 10) / kMatrixHeight) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for (int y = 0; y < kMatrixHeight; y++)
{
heat[x][y] = (heat[x][y + 1] + heat[x][y + 2] + heat[x][y + 2]) / 3;
}
// Step 2. Randomly ignite new 'sparks' of heat
if (random8() < sparking)
{
heat[x][maxY] = qadd8(heat[x][maxY], random8(160, 255));
}
// Step 4. Map from heat cells to LED colors
for (int y = 0; y < kMatrixHeight; y++)
{
uint8_t colorIndex = 0;
if (up)
colorIndex = heat[x][y];
else
colorIndex = heat[x][(maxY) - y];
// Recommend that you use values 0-240 rather than
// the usual 0-255, as the last 15 colors will be
// 'wrapping around' from the hot end to the cold end,
// which looks wrong.
colorIndex = scale8(colorIndex, 240);
// override color 0 to ensure a black background
if (colorIndex != 0)
{
setPixelXY10(x, y, ColorFromPalette(palette, colorIndex, 255, LINEARBLEND));
}
}
}
}
uint8_t fire()
{
heatMap(HeatColors_p, true);
return 30;
}
uint8_t water()
{
heatMap(IceColors_p, false);
return 30;
}
uint8_t showSolidColor()
{
fill_solid(leds, NUM_LEDS, solidColor);
return 30;
}
uint8_t incrementalDrift() {
uint8_t stepwidth = 256 * (20 - 1) / NUM_LEDS;
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t bri = beatsin88(1 * 256 + (NUM_LEDS - i) * stepwidth, 0, 256);
leds[fibonacciToPhysicalOrder[i]] = ColorFromPalette(gCurrentPalette, 2.5 * i + gHue, bri, LINEARBLEND);
}
return 8;
}
// Pride2015 by Mark Kriegsman: https://gist.github.com/kriegsman/964de772d64c502760e5
// This function draws rainbows with an ever-changing,
// widely-varying set of parameters.
uint8_t pride(bool useFibonacciOrder) {
static uint16_t sPseudotime = 0;
static uint16_t sLastMillis = 0;
static uint16_t sHue16 = 0;
uint8_t sat8 = beatsin88( 87, 220, 250);
uint8_t brightdepth = beatsin88( 341, 96, 224);
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t hue16 = sHue16;//gHue * 256;
uint16_t hueinc16 = beatsin88(113, 1, 3000);
uint16_t ms = millis();
uint16_t deltams = ms - sLastMillis ;
sLastMillis = ms;
sPseudotime += deltams * msmultiplier;
sHue16 += deltams * beatsin88( 400, 5, 9);
uint16_t brightnesstheta16 = sPseudotime;
for ( uint16_t i = 0 ; i < NUM_LEDS; i++) {
hue16 += hueinc16;
uint8_t hue8 = hue16 / 256;
brightnesstheta16 += brightnessthetainc16;
uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth);
CRGB newcolor = CHSV( hue8, sat8, bri8);
uint16_t pixelnumber = i;
if (useFibonacciOrder) {
pixelnumber = fibonacciToPhysicalOrder[(NUM_LEDS - 1) - pixelnumber];
}
nblend(leds[pixelnumber], newcolor, 64);
}
return 15;
}
uint8_t pride1()
{
return pride(true);
}
uint8_t pride2()
{
return pride(false);
}
uint8_t radialPaletteShift()
{
for (uint8_t i = 0; i < NUM_LEDS; i++) {
// leds[i] = ColorFromPalette( currentPalette, gHue + sin8(i*16), brightness);
uint8_t index = fibonacciToPhysicalOrder[(NUM_LEDS - 1) - i];
leds[index] = ColorFromPalette(gCurrentPalette, i + gHue, 255, LINEARBLEND);
}
return 8;
}
uint8_t horizontalPaletteBlend()
{
uint8_t offset = 0;
for (uint8_t x = 0; x <= kMatrixWidth; x++)
{
CRGB color = ColorFromPalette(currentPalette, gHue + offset, 255, LINEARBLEND);
for (uint8_t y = 0; y <= kMatrixHeight; y++)
{
setPixelXY(x, y, color);
}
offset++;
}
return 15;
}
uint8_t verticalPaletteBlend()
{
uint8_t offset = 0;
for (uint8_t y = 0; y <= kMatrixHeight; y++)
{
CRGB color = ColorFromPalette(currentPalette, gHue + offset, 255, LINEARBLEND);
for (uint8_t x = 0; x <= kMatrixWidth; x++)
{
setPixelXY(x, y, color);
}
offset++;
}
return 15;
}
uint8_t nyan()
{
static uint8_t offset = 0;
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = ColorFromPalette(gCurrentPalette, ledRadii[j] + offset, ledAngles[j] - offset);
// leds[i] = CHSV(255 - ledRadii[j], 255, ledAngles[j] - offset);
}
EVERY_N_MILLISECONDS(15) { offset++; };
return 8;
}
uint8_t radialWavesWithCircular()
{
dimAll(253);
static uint8_t prevB = 0;
static bool spiral = false;
uint8_t b = beatsin8(8);
if(b < prevB){
random16_add_entropy(random());
if(random8() > 254) {
spiral = true;
}
}
prevB = b;
// EVERY_N_SECONDS(5) { spiral = true; }
if(spiral) {
static uint8_t angle = random8();
static uint8_t radius = 255;
setPixelAR(angle, radius, 24, 20, CRGB::White);
if(radius < 1) {
spiral = false;
radius = 255;
angle = random8();
}
radius -= 1;
angle -= 2;
}
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] |= ColorFromPalette(gCurrentPalette, ledRadii[j] - b);
}
return 1;
}
uint8_t circular()
{
dimAll(253);
static uint8_t offset = 0;
uint8_t angle = beat8(60);
uint8_t radius = beatsin8(16);
setPixelAR(angle, radius, 24, 20, ColorFromPalette(gCurrentPalette, offset));
// setPixelAR(angle, radius, 24, 20, CHSV(offset, 255, 255));
EVERY_N_MILLISECONDS(15) { offset++; };
return 8;
}
uint8_t radar()
{
dimAll(253);
static uint8_t offset = 0;
// uint8_t a = sin8(offset);
// uint8_t r = cos8(offset);
setPixelA(offset, 24, CRGB::Red);
EVERY_N_MILLISECONDS(15) { offset++; };
return 1;
}
uint8_t angular()
{
static uint8_t offset = 0;
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = ColorFromPalette(gCurrentPalette, ledAngles[j] + offset);
// leds[i] = CHSV(ledAngles[j] + offset, 255, 255);
}
EVERY_N_MILLISECONDS(15) { offset++; };
return 8;
}
uint8_t angular2()
{
static uint8_t offset = 0;
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = ColorFromPalette(gCurrentPalette, ledAngles[j] + offset, ledRadii[j]);
// leds[i] = CHSV(ledAngles[j] + offset, 255, 255 - ledRadii[j]);
}
EVERY_N_MILLISECONDS(15) { offset++; };
return 8;
}
uint8_t radial()
{
static uint8_t offset = 0;
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = ColorFromPalette(gCurrentPalette, ledRadii[j] + offset);
// leds[i] = CHSV(ledRadii[j] + offset, 255, 255);
}
EVERY_N_MILLISECONDS(15) { offset++; };
return 8;
}
uint8_t radial2()
{
static uint8_t offset = 0;
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = ColorFromPalette(gCurrentPalette, ledRadii[j] - offset);
// leds[i] = CHSV(ledRadii[j] + offset, ledAngles[j], 255);
}
EVERY_N_MILLISECONDS(15) { offset++; };
return 8;
}
uint8_t radialWaves()
{
static uint8_t offset = 0;
uint8_t b = beatsin8(8);
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = ColorFromPalette(gCurrentPalette, ledRadii[j] - b);
// leds[i] = CHSV(ledRadii[j] + offset, ledAngles[j], 255);
}
EVERY_N_MILLISECONDS(15) { offset++; };
return 1;
}
uint8_t radial3()
{
static uint8_t offset = 0;
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = ColorFromPalette(gCurrentPalette, ledRadii[j] + offset, ledAngles[j] - offset);
// leds[i] = CHSV(ledRadii[j] + offset, 255, ledAngles[j]);
}
EVERY_N_MILLISECONDS(15) { offset++; };
return 8;
}
CRGB scrollingHorizontalWashColor( uint8_t x, uint8_t y, unsigned long timeInMillis)
{
return CHSV( x + (timeInMillis / 10), 255, 255);
}
uint8_t horizontalRainbow()
{
unsigned long t = millis();
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = scrollingHorizontalWashColor(coordsX[j], coordsY[j], t);
}
return 8;
}
CRGB scrollingVerticalWashColor( uint8_t x, uint8_t y, unsigned long timeInMillis)
{
return CHSV( y + (timeInMillis / 10), 255, 255);
}
uint8_t verticalRainbow()
{
unsigned long t = millis();
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = scrollingVerticalWashColor(coordsX[j], coordsY[j], t);
}
return 8;
}
CRGB scrollingDiagonalWashColor( uint8_t x, uint8_t y, unsigned long timeInMillis)
{
return CHSV( x + y + (timeInMillis / 10), 255, 255);
}
uint8_t diagonalRainbow()
{
unsigned long t = millis();
for (uint8_t i = 0; i < NUM_LEDS; i++) {
uint8_t j = physicalToFibonacciOrder[i];
leds[i] = scrollingDiagonalWashColor(coordsX[j], coordsY[j], t);
}
return 8;
}
uint8_t wave()
{
const uint8_t scale = 256 / kMatrixWidth;
static uint8_t rotation = 0;
static uint8_t theta = 0;
static uint8_t waveCount = 1;
uint8_t n = 0;
switch (rotation) {
case 0:
for (int x = 0; x < kMatrixWidth; x++) {
n = quadwave8(x * 2 + theta) / scale;
setPixelXY(x, n, ColorFromPalette(currentPalette, x + gHue, 255, LINEARBLEND));
if (waveCount == 2)
setPixelXY(x, maxY - n, ColorFromPalette(currentPalette, x + gHue, 255, LINEARBLEND));
}
break;
case 1:
for (int y = 0; y < kMatrixHeight; y++) {
n = quadwave8(y * 2 + theta) / scale;
setPixelXY(n, y, ColorFromPalette(currentPalette, y + gHue, 255, LINEARBLEND));
if (waveCount == 2)
setPixelXY(maxX - n, y, ColorFromPalette(currentPalette, y + gHue, 255, LINEARBLEND));
}
break;
case 2:
for (int x = 0; x < kMatrixWidth; x++) {
n = quadwave8(x * 2 - theta) / scale;
setPixelXY(x, n, ColorFromPalette(currentPalette, x + gHue));
if (waveCount == 2)
setPixelXY(x, maxY - n, ColorFromPalette(currentPalette, x + gHue, 255, LINEARBLEND));
}
break;
case 3:
for (int y = 0; y < kMatrixHeight; y++) {
n = quadwave8(y * 2 - theta) / scale;
setPixelXY(n, y, ColorFromPalette(currentPalette, y + gHue, 255, LINEARBLEND));
if (waveCount == 2)
setPixelXY(maxX - n, y, ColorFromPalette(currentPalette, y + gHue, 255, LINEARBLEND));
}
break;
}
dimAll(255);
EVERY_N_SECONDS(10)
{
rotation = random(0, 4);
// waveCount = random(1, 3);
};
EVERY_N_MILLISECONDS(7) {
theta++;
}
return 8;
}
uint8_t pulse()
{
dimAll(200);
uint8_t maxSteps = 16;
static uint8_t step = maxSteps;
static uint8_t centerX = 0;
static uint8_t centerY = 0;
float fadeRate = 0.8;
if (step >= maxSteps)
{
centerX = random(kMatrixWidth);
centerY = random(kMatrixWidth);
step = 0;
}
if (step == 0)
{
drawCircle(centerX, centerY, step, ColorFromPalette(currentPalette, gHue, 255, LINEARBLEND));
step++;
}
else
{
if (step < maxSteps)
{
// initial pulse
drawCircle(centerX, centerY, step, ColorFromPalette(currentPalette, gHue, pow(fadeRate, step - 2) * 255, LINEARBLEND));
// secondary pulse
if (step > 3) {
drawCircle(centerX, centerY, step - 3, ColorFromPalette(currentPalette, gHue, pow(fadeRate, step - 2) * 255, LINEARBLEND));
}
step++;
}
else
{
step = -1;
}
}
return 30;
}
// ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb
// This function draws color waves with an ever-changing,
// widely-varying set of parameters, using a color palette.
void colorwaves( CRGB* ledarray, uint16_t numleds, CRGBPalette16& palette, bool useFibonacciOrder)
{
static uint16_t sPseudotime = 0;
static uint16_t sLastMillis = 0;
static uint16_t sHue16 = 0;
// uint8_t sat8 = beatsin88( 87, 220, 250);
uint8_t brightdepth = beatsin88( 341, 96, 224);
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t hue16 = sHue16;//gHue * 256;
uint16_t hueinc16 = beatsin88(113, 300, 1500);
uint16_t ms = millis();
uint16_t deltams = ms - sLastMillis ;
sLastMillis = ms;