-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathFunkyClouds.ino
1331 lines (1183 loc) · 32.1 KB
/
FunkyClouds.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
/*
TODO:
example show oscis+p
document caleidoscopes better
write better caleidoscopes...
improve and document emitters and oszillators
explaining one example step by step:
goal? what? how? why?
gridmapping for rotation + zoom
good interpolation for other matrix dimensions than 16*16
more move & stream functions
layers
palettes
link effects to areas
1D examples
2d example with more than 2 sines
speed up MSGEQ7 readings
DONE:
25.6. creating basic structure
setting up basic examples
26.6. MSGEQ7 Support
wrote more examples
27.6. improved documentation
added Move
added AutoRun
TODO list
Copy
29.6. rotate+mirror triangle
more examples
30.6. RenderCustomMatrix
added more comments
alpha version released
/*
/*
Funky Clouds Compendium (alpha version)
by Stefan Petrick
An ever growing list of examples, tools and toys
for creating one- and twodimensional LED effects.
Dedicated to the users of the FastLED v2.1 library
by Daniel Garcia and Mark Kriegsmann.
Provides basic and advanced helper functions.
Contains many examples how to creatively combine them.
Tested @ATmega2560 (runs propably NOT on an Uno or
anything else with less than 4kB RAM)
*/
#include <FastLED.h>
// define your LED hardware setup here
#define CHIPSET WS2812B
#define LED_PIN 13
#define COLOR_ORDER GRB
// set master brightness 0-255 here to adjust power consumption
// and light intensity
#define BRIGHTNESS 60
// enter your custom matrix size if it is NOT a 16*16 and
// check in that case the setup part and
// RenderCustomMatrix() and
// ShowFrame() for more comments
const uint8_t CUSTOM_WIDTH = 8;
const uint8_t CUSTOM_HEIGHT = 8;
// MSGEQ7 wiring on spectrum analyser shield
#define MSGEQ7_STROBE_PIN 4
#define MSGEQ7_RESET_PIN 5
#define AUDIO_LEFT_PIN 0
#define AUDIO_RIGHT_PIN 1
// all 2D effects will be calculated in this matrix size
// do not touch
const uint8_t WIDTH = 16;
const uint8_t HEIGHT = 16;
// number of LEDs based on fixed calculation matrix size
// do not touch
#define NUM_LEDS (WIDTH * HEIGHT)
// the rendering buffer (16*16)
// do not touch
CRGB leds[NUM_LEDS];
// your display buffer for your not 16*16 setup
CRGB leds2[CUSTOM_HEIGHT * CUSTOM_WIDTH];
// the oscillators: linear ramps 0-255
// modified only by MoveOscillators()
byte osci[4];
// sin8(osci) swinging between 0 - 15
// modified only by MoveOscillators()
byte p[4];
// storage of the 7 10Bit (0-1023) audio band values
// modified only by AudioRead()
int left[7];
int right[7];
// noise stuff
uint16_t speed = 10;
uint16_t scale = 50;
uint16_t scale2 = 30;
const uint8_t kMatrixWidth = 16;
const uint8_t kMatrixHeight = 16;
#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
uint8_t noise2[MAX_DIMENSION][MAX_DIMENSION];
static uint16_t x;
static uint16_t y;
static uint16_t z;
static uint16_t x2;
static uint16_t y2;
static uint16_t z2;
//palette stuff
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
/*
-------------------------------------------------------------------
Init Inputs and Outputs: LEDs and MSGEQ7
-------------------------------------------------------------------
*/
void setup() {
// use the following line only when working with a 16*16
// and delete everything in the function RenderCustomMatrix()
// at the end of the code; edit XY() to change your matrix layout
// right now it is doing a serpentine mapping
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds+5, NUM_LEDS-5);
// use this line only when using a custom size matrix
//FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds2, CUSTOM_HEIGHT * CUSTOM_WIDTH);
FastLED.setBrightness(BRIGHTNESS);
FastLED.setDither(0);
// just for debugging:
//Serial.begin(9600);
Serial.begin(38400);
InitMSGEQ7();
// Initialize our noise coordinates to some random values
x = random16();
y = random16();
z = random16();
x2 = random16();
y2 = random16();
z2 = random16();
}
/*
-------------------------------------------------------------------
The main program
-------------------------------------------------------------------
*/
void loop()
{
AutoRun();
// Comment AutoRun out and test examples seperately here
//Dots2();
// For discovering parameters of examples I reccomend to
// tinker with a renamed copy ...
}
/*
-------------------------------------------------------------------
Basic Helper functions:
XY translate 2 dimensional coordinates into an index
Line draw a line
Pixel draw a pixel
ClearAll empty the screenbuffer
MoveOscillators increment osci[] and calculate p[]=sin8(osci)
InitMSGEQ7 activate the MSGEQ7
ReadAudio get data from MSGEQ7 into left[7] and right[7]
-------------------------------------------------------------------
*/
// translates from x, y into an index into the LED array and
// finds the right index for a S shaped matrix
int XY(int x, int y) {
if(y > HEIGHT) {
y = HEIGHT;
}
if(y < 0) {
y = 0;
}
if(x > WIDTH) {
x = WIDTH;
}
if(x < 0) {
x = 0;
}
// for a serpentine layout reverse every 2nd row:
if(x % 2 == 1) {
return (x * (WIDTH) + (HEIGHT - y -1));
}
else {
// use that line only, if you have all rows beginning at the same side
return (x * (WIDTH) + y);
}
}
// Bresenham line algorythm based on 2 coordinates
void Line(int x0, int y0, int x1, int y1, byte color) {
int dx = abs(x1-x0), sx = x0 < x1 ? 1 : -1;
int dy = -abs(y1-y0), sy = y0 < y1 ? 1 : -1;
int err = dx + dy, e2;
for(;;) {
leds[XY(x0, y0)] = CHSV(color, 255, 255);
if (x0 == x1 && y0 == y1) break;
e2 = 2 * err;
if (e2 > dy) {
err += dy;
x0 += sx;
}
if (e2 < dx) {
err += dx;
y0 += sy;
}
}
}
// write one pixel with HSV color to coordinates
void Pixel(int x, int y, byte color) {
leds[XY(x, y)] = CHSV(color, 255, 255);
}
// delete the screenbuffer
void ClearAll()
{
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = 0;
}
}
/*
Oscillators and Emitters
*/
// set the speeds (and by that ratios) of the oscillators here
void MoveOscillators() {
osci[0] = osci[0] + 5;
osci[1] = osci[1] + 2;
osci[2] = osci[2] + 3;
osci[3] = osci[3] + 4;
for(int i = 0; i < 4; i++) {
p[i] = sin8(osci[i]) / 17; //why 17? to keep the result in the range of 0-15 (matrix size)
}
}
// wake up the MSGEQ7
void InitMSGEQ7() {
pinMode(MSGEQ7_RESET_PIN, OUTPUT);
pinMode(MSGEQ7_STROBE_PIN, OUTPUT);
digitalWrite(MSGEQ7_RESET_PIN, LOW);
digitalWrite(MSGEQ7_STROBE_PIN, HIGH);
}
// get the data from the MSGEQ7
// (still fucking slow...)
void ReadAudio() {
digitalWrite(MSGEQ7_RESET_PIN, HIGH);
digitalWrite(MSGEQ7_RESET_PIN, LOW);
for(byte band = 0; band < 7; band++) {
digitalWrite(MSGEQ7_STROBE_PIN, LOW);
delayMicroseconds(30);
left[band] = analogRead(AUDIO_LEFT_PIN);
right[band] = analogRead(AUDIO_RIGHT_PIN);
digitalWrite(MSGEQ7_STROBE_PIN, HIGH);
}
}
/*
-------------------------------------------------------------------
Functions for manipulating existing data within the screenbuffer:
DimAll scales the brightness of the screenbuffer down
Caleidoscope1 mirror one quarter to the other 3 (and overwrite them)
Caleidoscope2 rotate one quarter to the other 3 (and overwrite them)
Caleidoscope3 useless bullshit?!
Caleidoscope4 rotate and add the complete screenbuffer 3 times
Caleidoscope5 copy a triangle from the first quadrant to the other half
Caleidoscope6
SpiralStream stream = give it a nice fading tail
HorizontalStream
VerticalStream
VerticalMove move = just move it as it is one line down
Copy copy a rectangle
RotateTriangle copy + rotate a triangle (in 8*8)
MirrorTriangle copy + mirror a triangle (in 8*8)
RainbowTriangle static draw for debugging
-------------------------------------------------------------------
*/
// scale the brightness of the screenbuffer down
void DimAll(byte value)
{
for(int i = 0; i < NUM_LEDS; i++) {
leds[i].nscale8(value);
}
}
/*
Caleidoscope1 mirrors from source to A, B and C
y
| |
| B | C
|_______________
| |
|source | A
|_______________ x
*/
void Caleidoscope1() {
for(int x = 0; x < WIDTH / 2 ; x++) {
for(int y = 0; y < HEIGHT / 2; y++) {
leds[XY( WIDTH - 1 - x, y )] = leds[XY( x, y )]; // copy to A
leds[XY( x, HEIGHT - 1 - y )] = leds[XY( x, y )]; // copy to B
leds[XY( WIDTH - 1 - x, HEIGHT - 1 - y )] = leds[XY( x, y )]; // copy to C
}
}
}
/*
Caleidoscope2 rotates from source to A, B and C
y
| |
| C | B
|_______________
| |
|source | A
|_______________ x
*/
void Caleidoscope2() {
for(int x = 0; x < WIDTH / 2 ; x++) {
for(int y = 0; y < HEIGHT / 2; y++) {
leds[XY( WIDTH - 1 - x, y )] = leds[XY( y, x )]; // rotate to A
leds[XY( WIDTH - 1 - x, HEIGHT - 1 - y )] = leds[XY( x, y )]; // rotate to B
leds[XY( x, HEIGHT - 1 - y )] = leds[XY( y, x )]; // rotate to C
}
}
}
// adds the color of one quarter to the other 3
void Caleidoscope3() {
for(int x = 0; x < WIDTH / 2 ; x++) {
for(int y = 0; y < HEIGHT / 2; y++) {
leds[XY( WIDTH - 1 - x, y )] += leds[XY( y, x )]; // rotate to A
leds[XY( WIDTH - 1 - x, HEIGHT - 1 - y )] += leds[XY( x, y )]; // rotate to B
leds[XY( x, HEIGHT - 1 - y )] += leds[XY( y, x )]; // rotate to C
}
}
}
// add the complete screenbuffer 3 times while rotating
void Caleidoscope4() {
for(int x = 0; x < WIDTH ; x++) {
for(int y = 0; y < HEIGHT ; y++) {
leds[XY( WIDTH - 1 - x, y )] += leds[XY( y, x )]; // rotate to A
leds[XY( WIDTH - 1 - x, HEIGHT - 1 - y )] += leds[XY( x, y )]; // rotate to B
leds[XY( x, HEIGHT - 1 - y )] += leds[XY( y, x )]; // rotate to C
}
}
}
// rotate, duplicate and copy over a triangle from first sector into the other half
// (crappy code)
void Caleidoscope5() {
for(int x = 1; x < 8 ; x++) {
leds[XY(7 - x, 7 )] += leds[XY(x, 0)];
} //a
for(int x = 2; x < 8 ; x++) {
leds[XY(7 - x, 6 )] += leds[XY(x, 1)];
} //b
for(int x = 3; x < 8 ; x++) {
leds[XY(7 - x, 5 )] += leds[XY(x, 2)];
} //c
for(int x = 4; x < 8 ; x++) {
leds[XY(7 - x, 4 )] += leds[XY(x, 3)];
} //d
for(int x = 5; x < 8 ; x++) {
leds[XY(7 - x, 3 )] += leds[XY(x, 4)];
} //e
for(int x = 6; x < 8 ; x++) {
leds[XY(7 - x, 2 )] += leds[XY(x, 5)];
} //f
for(int x = 7; x < 8 ; x++) {
leds[XY(7 - x, 1 )] += leds[XY(x, 6)];
} //g
}
void Caleidoscope6() {
for(int x = 1; x < 8 ; x++) {
leds[XY(7 - x, 7 )] = leds[XY(x, 0)];
} //a
for(int x = 2; x < 8 ; x++) {
leds[XY(7 - x, 6 )] = leds[XY(x, 1)];
} //b
for(int x = 3; x < 8 ; x++) {
leds[XY(7 - x, 5 )] = leds[XY(x, 2)];
} //c
for(int x = 4; x < 8 ; x++) {
leds[XY(7 - x, 4 )] = leds[XY(x, 3)];
} //d
for(int x = 5; x < 8 ; x++) {
leds[XY(7 - x, 3 )] = leds[XY(x, 4)];
} //e
for(int x = 6; x < 8 ; x++) {
leds[XY(7 - x, 2 )] = leds[XY(x, 5)];
} //f
for(int x = 7; x < 8 ; x++) {
leds[XY(7 - x, 1 )] = leds[XY(x, 6)];
} //g
}
// create a square twister
// x and y for center, r for radius
void SpiralStream(int x,int y, int r, byte dim) {
for(int d = r; d >= 0; d--) { // from the outside to the inside
for(int i = x-d; i <= x+d; i++) {
leds[XY(i,y-d)] += leds[XY(i+1,y-d)]; // lowest row to the right
leds[XY(i,y-d)].nscale8( dim );
}
for(int i = y-d; i <= y+d; i++) {
leds[XY(x+d,i)] += leds[XY(x+d,i+1)]; // right colum up
leds[XY(x+d,i)].nscale8( dim );
}
for(int i = x+d; i >= x-d; i--) {
leds[XY(i,y+d)] += leds[XY(i-1,y+d)]; // upper row to the left
leds[XY(i,y+d)].nscale8( dim );
}
for(int i = y+d; i >= y-d; i--) {
leds[XY(x-d,i)] += leds[XY(x-d,i-1)]; // left colum down
leds[XY(x-d,i)].nscale8( dim );
}
}
}
// give it a linear tail to the side
void HorizontalStream(byte scale)
{
for(int x = 1; x < WIDTH ; x++) {
for(int y = 0; y < HEIGHT; y++) {
leds[XY(x,y)] += leds[XY(x-1,y)];
leds[XY(x,y)].nscale8( scale );
}
}
for(int y = 0; y < HEIGHT; y++)
leds[XY(0,y)].nscale8(scale);
}
// give it a linear tail downwards
void VerticalStream(byte scale)
{
for(int x = 0; x < WIDTH ; x++) {
for(int y = 1; y < HEIGHT; y++) {
leds[XY(x,y)] += leds[XY(x,y-1)];
leds[XY(x,y)].nscale8( scale );
}
}
for(int x = 0; x < WIDTH; x++)
leds[XY(x,0)].nscale8(scale);
}
// just move everything one line down
void VerticalMove() {
for(int y = 15; y > 0; y--) {
for(int x = 0; x < 16; x++) {
leds[XY(x, y)] = leds[XY(x, y-1)];
}
}
}
// copy the rectangle defined with 2 points x0, y0, x1, y1
// to the rectangle beginning at x2, x3
void Copy(byte x0, byte y0, byte x1, byte y1, byte x2, byte y2) {
for(int y = y0; y < y1+1; y++) {
for(int x = x0; x < x1+1; x++) {
leds[XY(x+x2-x0, y + y2-y0)] = leds[XY(x, y)];
}
}
}
// rotate + copy triangle (8*8)
void RotateTriangle() {
for(int x = 1; x < 8; x++) {
for(int y = 0; y<x; y++) {
leds[XY(x, 7-y)] = leds[XY(7-x, y)];
}
}
}
// mirror + copy triangle (8*8)
void MirrorTriangle() {
for(int x = 1; x < 8; x++) {
for(int y = 0; y<x; y++) {
leds[XY(7-y, x)] = leds[XY(7-x, y)];
}
}
}
// draw static rainbow triangle pattern (8x8)
// (just for debugging)
void RainbowTriangle() {
for(int i = 0; i < 8; i++) {
for(int j = 0; j<=i; j++) {
Pixel(7-i, j, i*j*4);
}
}
}
/*
-------------------------------------------------------------------
Examples how to combine functions in order to create an effect
...or: how to visualize some of the following data
osci[0] ... osci[3] (0-255) triangle
p[0] ... p[3] (0-15) sinus
left[0] ... left[6] (0-1023) values of 63Hz, 160Hz, ...
right[0] ... right[6] (0-1023)
effects based only on oscillators (triangle/sine waves)
AutoRun shows everything that follows
SlowMandala red slow
Dots1 2 arround one
Dots2 stacking sines
SlowMandala2 just nice and soft
SlowMandala3 just nice and soft
Mandala8 copy one triangle all over
effects based on audio data (could be also linked to oscillators)
MSGEQtest colorfull 2 chanel 7 band analyzer
MSGEQtest2 2 frequencies linked to dot emitters in a spiral mandala
MSGEQtest3 analyzer 2 bars
MSGEQtest4 analyzer x 4 (as showed on youtube)
AudioSpiral basedrum/snare linked to red/green emitters
MSGEQtest5 one channel 7 band spectrum analyzer (spiral fadeout)
MSGEQtest6 classic analyzer, slow falldown
MSGEQtest7 spectrum mandala, color linked to low frequencies
MSGEQtest8 spectrum mandala, color linked to osci
MSGEQtest9 falling spectogram
CopyTest
Audio1
Audio2
Audio3
Audio4
CaleidoTest1
Caleidotest2
Audio5
Audio6
-------------------------------------------------------------------
*/
// all examples together
void AutoRun() {
/*
// all oscillator based:
for(int i = 0; i < 300; i++) {Dots1();}
for(int i = 0; i < 300; i++) {Dots2();}
SlowMandala();
SlowMandala2();
SlowMandala3();
for(int i = 0; i < 300; i++) {Mandala8();}
// all MSGEQ7 based:
for(int i = 0; i < 500; i++) {MSGEQtest();}
for(int i = 0; i < 500; i++) {MSGEQtest2();}
for(int i = 0; i < 500; i++) {MSGEQtest3();}
for(int i = 0; i < 500; i++) {MSGEQtest4();}
for(int i = 0; i < 500; i++) {AudioSpiral();}
for(int i = 0; i < 500; i++) {MSGEQtest5();}
for(int i = 0; i < 500; i++) {MSGEQtest6();}
for(int i = 0; i < 500; i++) {MSGEQtest7();}
for(int i = 0; i < 500; i++) {MSGEQtest8();}
for(int i = 0; i < 500; i++) {MSGEQtest9();}
for(int i = 0; i < 500; i++) {CopyTest();}
for(int i = 0; i < 500; i++) {Audio1();}
for(int i = 0; i < 500; i++) {Audio2();}
for(int i = 0; i < 500; i++) {Audio3();}
for(int i = 0; i < 500; i++) {Audio4();}
for(int i = 0; i < 500; i++) {CaleidoTest1();}
for(int i = 0; i < 500; i++) {CaleidoTest2();}
for(int i = 0; i < 500; i++) {Audio5();}
for(int i = 0; i < 500; i++) {Audio6();}
for(int i = 0; i < 500; i++) {
NoiseExample1();
}
for(int i = 0; i < 500; i++) {
NoiseExample2();
}
for(int i = 0; i < 500; i++) {
NoiseExample3();
}
//SpeedTest();
for(int i = 0; i < 500; i++) {
NoiseExample4();
}
//for(int i = 0; i < 500; i++) {NoiseExample5();}
*/
//NoiseExample6();
NoiseExample7();
}
// red, 4 spirals, one dot emitter
// demonstrates SpiralStream and Caleidoscope
// (psychedelic)
void SlowMandala() {
for(int i = 0; i < 16; i++) {
for(int j = 0; j < 16; j++) {
Pixel(i,j,1);
SpiralStream(4, 4, 4, 127);
Caleidoscope1();
ShowFrame();
FastLED.delay(50);
}
}
}
// 2 oscillators flying arround one ;)
void Dots1() {
MoveOscillators();
//2 lissajous dots red
leds[XY(p[0],p[1])] = CHSV (1 , 255, 255);
leds[XY(p[2],p[3])] = CHSV (1 , 255, 150);
//average of the coordinates in yellow
Pixel((p[2]+p[0])/2, (p[1]+p[3])/2, 50);
ShowFrame();
FastLED.delay(20);
HorizontalStream(125);
}
// x and y based on 3 sine waves
void Dots2() {
MoveOscillators();
Pixel((p[2]+p[0]+p[1])/3, (p[1]+p[3]+p[2])/3, osci[3]);
ShowFrame();
FastLED.delay(20);
HorizontalStream(125);
}
// beautifull but periodic
void SlowMandala2() {
for(int i = 1; i < 8; i++) {
for(int j = 0; j < 16; j++) {
MoveOscillators();
Pixel(j,i, (osci[0]+osci[1])/2);
SpiralStream(4, 4, 4, 127);
Caleidoscope2();
ShowFrame();
FastLED.delay(20);
}
}
}
// same with a different timing
void SlowMandala3() {
for(int i = 0; i < 16; i++) {
for(int j = 0; j < 16; j++) {
MoveOscillators();
Pixel(j,j, (osci[0]+osci[1])/2);
SpiralStream(4, 4, 4, 127);
Caleidoscope2();
ShowFrame();
FastLED.delay(20);
}
}
}
// 2 lissajou dots *2 *4
void Mandala8() {
MoveOscillators();
Pixel(p[0]/2, p[1]/2, osci[2]);
Pixel(p[2]/2, p[3]/2, osci[3]);
Caleidoscope5();
Caleidoscope2();
HorizontalStream(110);
ShowFrame();
}
// colorfull 2 chanel 7 band analyzer
void MSGEQtest() {
ReadAudio();
for(int i = 0; i < 7; i++) {
Pixel(i, 16-left[i]/64, left[i]/4);
}
for(int i = 0; i < 7; i++) {
Pixel(8+i, 16-right[i]/64, right[i]/4);
}
ShowFrame();
VerticalStream(120);
}
// 2 frequencies linked to dot emitters in a spiral mandala
void MSGEQtest2() {
ReadAudio();
if (left[0]>500) {
Pixel(0,0,1);
Pixel(1,1,1);
}
if (left[2]>200) {
Pixel(2,2,100);
}
if (left[6]>200) {
Pixel(5,0,200);
}
SpiralStream(4, 4, 4, 127);
Caleidoscope1();
ShowFrame();
}
// analyzer 2 bars
void MSGEQtest3() {
ReadAudio();
for(int i = 0; i < 8; i++) {
Pixel(i, 16-left[0]/64, 1);
}
for(int i=8; i < 16; i++) {
Pixel(i, 16-left[4]/64, 100);
}
ShowFrame();
VerticalStream(120);
}
// analyzer x 4 (as showed on youtube)
void MSGEQtest4() {
ReadAudio();
for(int i = 0; i < 7; i++) {
Pixel(7-i, 8-right[i]/128, i*10);
}
Caleidoscope2();
ShowFrame();
DimAll(240);
}
// basedrum/snare linked to red/green emitters
void AudioSpiral() {
MoveOscillators();
SpiralStream(7, 7, 7, 130);
SpiralStream(4, 4, 4, 122);
SpiralStream(11, 11, 3, 122);
ReadAudio();
if (left[1] > 500) {
leds[2,1] = CHSV (1 , 255, 255);
}
if (left[4] > 500) {
leds[XY(random(15),random(15))] = CHSV (100 , 255, 255);
}
ShowFrame();
DimAll(250);
}
// one channel 7 band spectrum analyzer (spiral fadeout)
void MSGEQtest5() {
ReadAudio();
for(int i = 0; i < 7; i++) {
Line(2*i, 16-left[i]/64, 2*i, 15, i*10);
Line(1+2*i, 16-left[i]/64, 1+2*i, 15, i*10);
}
ShowFrame();
SpiralStream(7, 7, 7, 120);
}
// classic analyzer, slow falldown
void MSGEQtest6() {
ReadAudio();
for(int i = 0; i < 7; i++) {
Line(2*i, 16-left[i]/64, 2*i, 15, i*10);
Line(1+2*i, 16-left[i]/64, 1+2*i, 15, i*10);
}
ShowFrame();
VerticalStream(170);
}
// geile Scheiße
// spectrum mandala, color linked to 160Hz band
void MSGEQtest7() {
MoveOscillators();
ReadAudio();
for(int i = 0; i < 7; i++) {
Pixel(7-i, 8-right[i]/128, i*10+right[1]/8);
}
Caleidoscope5();
Caleidoscope1();
ShowFrame();
DimAll(240);
}
// spectrum mandala, color linked to osci
void MSGEQtest8() {
MoveOscillators();
ReadAudio();
for(int i = 0; i < 7; i++) {
Pixel(7-i, 8-right[i]/128, i*10+osci[1]);
}
Caleidoscope5();
Caleidoscope2();
ShowFrame();
DimAll(240);
}
// falling spectogram
void MSGEQtest9() {
ReadAudio();
for(int i = 0; i < 7; i++) {
leds[XY(i*2,0)] = CHSV(i*27, 255, right[i]/3); // brightness should be divided by 4
leds[XY(1+i*2,0)] = CHSV(i*27, 255, left[i]/3);
}
leds[XY(14,0)] = 0;
leds[XY(15,0)] = 0;
ShowFrame();
VerticalMove();
}
// 9 analyzers
void CopyTest() {
ReadAudio();
for(int i = 0; i < 5; i++) {
Line(i, 4- left[i]/256, i, 4, i*10);
}
Copy(0,0, 4, 4, 5, 0);
Copy(0,0, 4, 4, 10, 0);
Copy(0,0,14,4,0,5);
Copy(0,0, 14, 4, 0, 10);
ShowFrame();
DimAll(200);
}
// test scale
// NOT WORKING as intended YET!
void CopyTest2() {
ReadAudio();
for(int i = 0; i < 5; i++) {
Line(i*2, 4- left[i]/128, i*2, 4, i*10);
}
Scale(0,0, 4, 4,
7,7, 15, 15);
ShowFrame();
DimAll(200);
}
// rechtangle 0-1 -> 2-3
// NOT WORKING as intended YET!
void Scale(int x0, int y0, int x1, int y1, int x2, int y2 ,int x3, int y3) {
for(int y = y2; y < y3+1; y++) {
for(int x = x2; x < x3+1; x++) {
leds[XY(x,y)] = leds[XY(
x0 + ( (x * (x1-x0)) / (x3-x1) ),
y0 + ( (y * (y1-y0)) / (y3-y1) ) )];
}
}
}
// line spectogram mandala
void Audio1() {
ReadAudio();
for(int i = 0; i < 5; i++) {
Line(3*i, 16-left[i]/64, 3*(i+1), 16-left[i+1]/64, 255-i*15);
}
Caleidoscope4();
ShowFrame();
DimAll(10);
}
// line analyzer with stream
void Audio2() {
ReadAudio();
for(int i = 0; i < 5; i++) {
Line(3*i, 16-left[i]/64, 3*(i+1), 16-left[i+1]/64, 255-i*15);
}
ShowFrame();
HorizontalStream(120);
}
void Audio3() {
ReadAudio();
for(int i = 0; i < 7; i++) {
leds[XY(6-i,right[i]/ 128)] = CHSV(i*27, 255, right[i]);
} // brightness should be divided by 4
Caleidoscope6();
Caleidoscope2();
ShowFrame();
DimAll(255);
}
void Audio4() {
ReadAudio();
for(int i = 0; i < 5; i++) {
Line(3*i, 8-left[i]/128, 3*(i+1), 8-left[i+1]/128, i*left[i]/32);
}
Caleidoscope4();
ShowFrame();
DimAll(12);
}
void CaleidoTest1() {
ReadAudio();
for(int i = 0; i < 7; i++) {
Line(i, left[i]/256, i,0,left[i]/32);
}
RotateTriangle();
Caleidoscope2(); //copy + rotate
ShowFrame();
DimAll(240);
}
void CaleidoTest2() {
MoveOscillators();
ReadAudio();
for(int i = 0; i < 7; i++) {
Line(i, left[i]/200, i, 0, (left[i]/16)+150);
}
MirrorTriangle();
Caleidoscope1(); //mirror + rotate
ShowFrame();
DimAll(240);
}
void Audio5() {
ReadAudio();
for(int i = 0; i < 5; i++) {
Line(
3 * i, 8 - left[i] / 128, // from
3 * (i+1), 8 - left[i+1] / 128, // to
i * 30);
} // color
Caleidoscope4();
ShowFrame();
DimAll(9);
}
void Audio6() {
ReadAudio();
for(int i = 0; i < 5; i++) {
Line(
3 * i, 8 - left[i] / 128, // from
3 * (i+1), 8 - left[i+1] / 128, // to
i * 10); // lolor
Line(
15-(3 * i), 7 + left[i] / 128, // from
15-(3 * (i+1)), 7 + left[i+1] / 128, // to
i * 10); // color
}
ShowFrame();
DimAll(200);
//ClearAll();
}
/*
-------------------------------------------------------------------
Testcode for mapping the 16*16 calculation buffer to your
custom matrix size
-------------------------------------------------------------------
*/
// describe your matrix layout here:
// P.S. If you use a 8*8 just remove the */ and /*
void RenderCustomMatrix() {
for(int x = 0; x < CUSTOM_WIDTH; x++) {
for(int y = 0; y < CUSTOM_HEIGHT; y++) {
// position in the custom array
leds2[x + x * y] =
// positions(s) in the source 16*16
// in this example it interpolates between just 2 diagonal touching pixels
(leds[XY(x*2, y*2)] + // first point added to
leds[XY(1+(x*2), 1+(y*2))]) // second point
; // divided by 2 to get the average color
}
}
}