-
Notifications
You must be signed in to change notification settings - Fork 0
/
ARD_W2812_7mod_master_sputnik_materil_nft.ino
1832 lines (1551 loc) · 62 KB
/
ARD_W2812_7mod_master_sputnik_materil_nft.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 <FastLED.h> //https://github.com/FastLED/FastLED
#include <arduinoFFT.h> //https://github.com/kosme/arduinoFFT
#include <IRremote.h> //https://github.com/z3t0/Arduino-IRremote
#include <EEPROM.h>
//#define NUM_LEDS_60 //OR remote control model select
#define RC1
///#define pinIR 3
#ifdef NUM_LEDS_60 //for test
//#define NUM_LEDS 60
#define NUM_LEDS 16
#else
#define NUM_LEDS 100 //number of LEDs //60 // How many leds in your strip?
#endif
#define CHANGE_INTERVAL 50 // 50 .. 150 ms interval for increase value buttons
#define CHANGE_INTERVAL_SELECT_BUTTON 150 // ~150 ms interval for select button
#define SOUND_CHANGE_INTERVAL 256 //350 //150 ms 350 ms
//#define PAUSE_SEC 3 //seconds
#define SERIAL_ON_INTERVAL1 50 //20 //100 //ms mode3
#define SERIAL_OFF_INTERVAL1 10
#define PULSE_INTERVAL 10 //seconds swith on and switch off mode 4
#define SEGMENTS_ON_INTERVAL 10 //seconds mode 5
#define DATA_PIN 2 // For led chips like Neopixels, which have a data line, ground, and power, you just need to define DATA_PIN
#define CHANGE_MODE_PIN 11
#define DECREASE_PIN 12
#define INCREASE_PIN 13
#define NUNMBER_MODES 9 //7 8 9
#define NUNMBER_SECTORS 5 //6 //8
#ifdef NUM_LEDS_60
#define FIRST_1_SECTOR_N_LED 0 //3
#define LAST_1_SECTOR_N_LED 2
#define FIRST_2_SECTOR_N_LED 3 //3
#define LAST_2_SECTOR_N_LED 5
#define FIRST_3_SECTOR_N_LED 6 //3
#define LAST_3_SECTOR_N_LED 8
#define FIRST_4_SECTOR_N_LED 9 //3
#define LAST_4_SECTOR_N_LED 11
#define FIRST_5_SECTOR_N_LED 12 //2
#define LAST_5_SECTOR_N_LED 13
#define FIRST_6_SECTOR_N_LED 14 //2
#define LAST_6_SECTOR_N_LED 15
#else
#define FIRST_1_SECTOR_N_LED 0
#define LAST_1_SECTOR_N_LED 53 //54 26 & 27 mid 26-0 together 27-57 27 26 28 25 29 24 30 23 31 22 32 21 33 20 34 19 35 18 36 17 37 16 38 15 39 14 40 13
//41 12 42 11 43 10 44 9 45 8 46 7 47 6 48 5 49 4 50 3 51 2 52 1 53 0
//26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
//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
#define FIRST_2_SECTOR_N_LED 54 //6 54 55 56 57 58 59
#define LAST_2_SECTOR_N_LED 59
#define FIRST_3_SECTOR_N_LED 60 //6 60 61 62 63 64 65
#define LAST_3_SECTOR_N_LED 65
#define FIRST_4_SECTOR_N_LED 66 //12 71 72 70 73 69 74 68 75 67 76 66 77
#define LAST_4_SECTOR_N_LED 77
#define FIRST_5_SECTOR_N_LED 78 //22 88 89 87 90 86 91 85 92 84 93 83 94 82 95 81 96 80 97 79 98 78 99
#define LAST_5_SECTOR_N_LED 99
#endif
#define TEMPERATURE_1 Tungsten40W //2600 Kelvin
#define TEMPERATURE_2 Tungsten100W //2850 Kelvin
#define TEMPERATURE_3 Halogen //3200 Kelvin
#define TEMPERATURE_4 CarbonArc //5200 Kelvin
#define TEMPERATURE_5 HighNoonSun //5400 Kelvin
#define TEMPERATURE_6 DirectSunlight //6000 Kelvin
#define TEMPERATURE_7 OvercastSky //7000 Kelvin
#define TEMPERATURE_8 ClearBlueSky //20000 Kelvin
#define SELECT_TEMPERATURE TEMPERATURE_4
#define MIN_BRIGHTNESS 0
#define MIN_BRIGHTNESS_1_MODE 3
#define MIN_BRIGHTNESS_2_MODE 3
#define MIN_BRIGHTNESS_3_MODE 5
#define MIN_BRIGHTNESS_4_MODE 3
#define MIN_BRIGHTNESS_5_MODE 3
//mode 6 7
#define MIN_LIGHTMUSIC_BRIGHTNESS 5
#define MAX_LIGHTMUSIC_BRIGHTNESS 255
#define W_SEC_MIN_LIGHTMUSIC_BRIGHTNESS 3 //WHITE SECTOR
#define W_SEC_MAX_LIGHTMUSIC_BRIGHTNESS 250 //WHITE SECTOR
//EQ 6 & 7 mode
#define SEC_1_MIN_LIGHTMUSIC_BRIGHTNESS 2
#define SEC_1_MAX_LIGHTMUSIC_BRIGHTNESS 128
#define SEC_2_MIN_LIGHTMUSIC_BRIGHTNESS 5
#define SEC_2_MAX_LIGHTMUSIC_BRIGHTNESS 248
#define SEC_3_MIN_LIGHTMUSIC_BRIGHTNESS 5
#define SEC_3_MAX_LIGHTMUSIC_BRIGHTNESS 248
#define SEC_4_MIN_LIGHTMUSIC_BRIGHTNESS 7
#define SEC_4_MAX_LIGHTMUSIC_BRIGHTNESS 199
#define SEC_5_MIN_LIGHTMUSIC_BRIGHTNESS 7
#define SEC_5_MAX_LIGHTMUSIC_BRIGHTNESS 254
//#define SEC_6_MIN_LIGHTMUSIC_BRIGHTNESS 25
//#define SEC_6_MAX_LIGHTMUSIC_BRIGHTNESS 255
//#define SEC_7_MIN_LIGHTMUSIC_BRIGHTNESS 25
//#define SEC_7_MAX_LIGHTMUSIC_BRIGHTNESS 255
//
//#define SEC_8_MIN_LIGHTMUSIC_BRIGHTNESS 25
//#define SEC_8_MAX_LIGHTMUSIC_BRIGHTNESS 255
#define MAX_BRIGHTNESS_1_MODE 255
#define MAX_BRIGHTNESS_4_MODE 120
#define MAX_BRIGHTNESS_5_MODE 255
#define MAX_BRIGHTNESS 255 // MAX ! 255 !
#define MAX_COLOR 255 //HUE transform 0..255
//mode 1
#define BR_STEP_1_MODE 3 // 1 3 5 10 brightness increase decrease step
//mode 2
#define BR_STEP_2_MODE 25 //1 3 5 10 brightness increase decrease step
#define COLOR_STEP_2_MODE 5 // 1 2 3 5 10 25 HUSE Color increase decrease step
#define RENEW_INTERVAL 1 //second
#define WHITE_SECTOR_2 1
#define MIN_MIC_LEVEL 0
#define MAX_MIC_LEVEL 630
//mode 3
#define BR_STEP_3_MODE 5 //1 3 5 10 25 brightness increase decrease step
#define MIN_SERIAL_ON_INTERVAL 1
#define MAX_SERIAL_ON_INTERVAL 250 //milliseconds
#define SERIAL_HOLD_ON_TIME 3 //seconds
//4 mode
#define MIN_PULSE_INTERVAL 1 //mode 4
#define MAX_PULSE_INTERVAL 100 //seconds
//5 mode
#define BR_STEP_5_MODE 5 //1 3 5 10 25 brightness increase decrease step
#define MIN_SWITCH_INTERVAl 1 //sec
#define MAX_SWITCH_INTERVAl 1000
//7 mode
#define WHITE_SECTOR 1
#define SAMPLES 32 //64 //Must be a power of 2
#define xres 16 //32 // Total number of columns in the display, must be <= SAMPLES/2
#define yres 255 // Total number of rows in the display
byte sectors_eq_arr[(NUNMBER_SECTORS + 1)][2] = { {0,0},
{SEC_1_MIN_LIGHTMUSIC_BRIGHTNESS, SEC_1_MAX_LIGHTMUSIC_BRIGHTNESS},
{SEC_2_MIN_LIGHTMUSIC_BRIGHTNESS, SEC_2_MAX_LIGHTMUSIC_BRIGHTNESS},
{SEC_3_MIN_LIGHTMUSIC_BRIGHTNESS, SEC_3_MAX_LIGHTMUSIC_BRIGHTNESS},
{SEC_4_MIN_LIGHTMUSIC_BRIGHTNESS, SEC_4_MAX_LIGHTMUSIC_BRIGHTNESS},
{SEC_5_MIN_LIGHTMUSIC_BRIGHTNESS, SEC_5_MAX_LIGHTMUSIC_BRIGHTNESS} };
byte serial_LED_n[NUM_LEDS] = {27, 26, 28, 25, 29, 24, 30, 23, 31, 22, 32, 21, 33, 20, 34, 19, 35, 18, 36, 17, 37, 16, 38, 15, 39, 14, 40, 13, 41, 12, 42, 11, 43, 10,
44, 9, 45, 8, 46, 7, 47, 6, 48, 5, 49, 4, 50, 3, 51, 2, 52, 1, 53, 0, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 71, 72, 70, 73,
69, 74, 68, 75, 67, 76, 66, 77, 88, 89, 87, 90, 86, 91, 85, 92, 84, 93, 83, 94, 82, 95, 81, 96, 80, 97, 79, 98, 78, 99};
byte mem_mode = 0;
//mode 1
int n = 0;
int br = 0;
int br_button = 127; //0 .. 255 defalut value
byte current_mode = 1;
CRGB leds[NUM_LEDS]; // Define the array of leds
//mode 2
byte white_sector_2 = WHITE_SECTOR_2 - 1;
int br_mic_level = 127; //0 .. 255
int Mic_level = 0;
int br_button_2 = 127;
int n_cur = 0;
//mode 3 speed up
int serial_on_interval = SERIAL_ON_INTERVAL1; //100;
int serial_off_interval = SERIAL_OFF_INTERVAL1;
bool turn_on_way = true;
bool bright_button_plus = false;
bool bright_button_minus = false;
byte k_mode3 = 1;
int br_button_3 = 127;
int pause_m3_ms = 0;
int br3_var = MAX_BRIGHTNESS;
int turn_off = false;
//mode 4
int pulse_interval_sec = PULSE_INTERVAL;
int br_pulse = 127; //0
int pulse_interval_ms = (int) 1000.0*pulse_interval_sec/510.0;
int br_button_4 = MAX_BRIGHTNESS_4_MODE;
int pause_ms = 0;
//mode 5
int n_sect = 0;
int n_led_segments[NUNMBER_SECTORS][2] = { {FIRST_1_SECTOR_N_LED, LAST_1_SECTOR_N_LED}, {FIRST_2_SECTOR_N_LED, LAST_2_SECTOR_N_LED}, {FIRST_3_SECTOR_N_LED, LAST_3_SECTOR_N_LED},
{FIRST_4_SECTOR_N_LED, LAST_4_SECTOR_N_LED}, {FIRST_5_SECTOR_N_LED, LAST_5_SECTOR_N_LED} };
int m5_switch_interval = 3; //MIN_SWITCH_INTERVAl MAX_SWITCH_INTERVAl
int br_button_5 = 127;
int br_var = MIN_BRIGHTNESS_5_MODE;
bool start_br_up = false;
//mode 7
byte white_sector = WHITE_SECTOR - 1;
//2 mode
byte selected_segment_2 = 1;
byte segments_colors_2[(NUNMBER_SECTORS + 1)] = {0, 127, 42, 84, 126, 168}; //225 EEPROM 6 7 8 9 10 11
//7 mode
byte selected_segment = 1;
byte segments_colors[(NUNMBER_SECTORS + 1)] = {0, 0, 80, 80, 126, 168}; // {0, 1 seg, 2 seg, 3 seg, 4 seg, 5 seg colors}
double vReal[SAMPLES];
double vImag[SAMPLES];
char data_avgs[xres];
byte br_freq[xres];
int yvalue;
int displaycolumn, displayvalue;
int peaks[xres];
arduinoFFT FFT = arduinoFFT();
long timer_cm = 0;
long timer_1 = 0;
long timer_2 = 0;
long timer_2_1 = 0;
long timer_2_2 = 0;
long timer_3 = 0;
long timer_3_1 = 0;
long timer_3_2 = 0;
long timer_3_3 = 0;
long timer_4 = 0;
long timer_4_1 = 0;
long timer_5 = 0;
long timer_5_1 = 0;
long timer_6 = 0;
long timer_7 = 0;
long timer_7_1 = 0;
long timer_7_2 = 0;
const int RECV_PIN = 7;
long code_command = 0;
bool br_button_plus = false;
bool br_button_minus = false;
int step = 0;
int c = 0;
bool turn = true;
byte seg = 1;
String str_1 = "";
String str_2 = "";
IRrecv irrecv(RECV_PIN);
decode_results results;
///int cur_code_command = 0;
///CNec IRLremote;
void Read_EEPROM_values();
void setup() {
Serial.begin(115200);
//EEPROM.begin(1024);
pinMode(DATA_PIN, OUTPUT);
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
pinMode(INCREASE_PIN, INPUT);
pinMode(DECREASE_PIN, INPUT);
pinMode(CHANGE_MODE_PIN, INPUT);
FastLED.setTemperature( SELECT_TEMPERATURE );
FastLED.setBrightness(0);
FastLED.show();
for (n = 0; n < NUM_LEDS; n++)
{
leds[n] = CRGB::White;
}
n = 0;
irrecv.enableIRIn();
/// if (!IRLremote.begin(pinIR))
/// Serial.println(F("Please choose a valid pin for IR RC"));
Read_EEPROM_values();
prepare_vals_for_new_mode();
}
void Read_EEPROM_values()
{
//1 mode
EEPROM.get( (6*sizeof(float)), br_button);
if ( (br_button < MIN_BRIGHTNESS_1_MODE) || (br_button > MAX_BRIGHTNESS_1_MODE) ) { br_button = 127; }
Serial.print(br_button);
Serial.print(F(" br_1 "));
//2 mode
EEPROM.get( (3*sizeof(float)), br_button_2);
if ( (br_button_2 < MIN_BRIGHTNESS_2_MODE) || (br_button_2 > MAX_BRIGHTNESS) ) { br_button_2 = 127; }
Serial.print(br_button_2);
Serial.print(F(" br_2 "));
Serial.print(F(" 2 mode colors: "));
//6 7 8 9 10 11
for(n_sect = 0; n_sect < NUNMBER_SECTORS; n_sect++)
{
EEPROM.get( ((6 + n_sect)*sizeof(float)), segments_colors_2[n_sect + 1]);
Serial.print(segments_colors_2[n_sect + 1]);
Serial.print(" ");
}
//3 mode
EEPROM.get( (0*sizeof(float)), serial_on_interval); //eeAddress, customVar
if (serial_on_interval < MIN_SERIAL_ON_INTERVAL) { serial_on_interval = MIN_SERIAL_ON_INTERVAL; }
if (serial_on_interval > MAX_SERIAL_ON_INTERVAL) { serial_on_interval = MAX_SERIAL_ON_INTERVAL; }
EEPROM.get( (1*sizeof(float)), br_button_3);
if ( (br_button_3 < MIN_BRIGHTNESS_3_MODE) || (br_button_3 > MAX_BRIGHTNESS) ) { br_button_3 = 127; }
Serial.print(F("3: "));
Serial.print(serial_on_interval);
Serial.print(F(" "));
Serial.print(br_button_3);
Serial.print(F(" "));
//4 mode
EEPROM.get( (2*sizeof(float)), pulse_interval_sec);
if (pulse_interval_sec < MIN_PULSE_INTERVAL) { pulse_interval_sec = MIN_PULSE_INTERVAL; }
if (pulse_interval_sec > MAX_PULSE_INTERVAL) { pulse_interval_sec = MAX_PULSE_INTERVAL; }
pulse_interval_ms = (int) 1000.0 * pulse_interval_sec / 510.0;
Serial.print(F("4: "));
Serial.print(pulse_interval_sec);
Serial.print(F(" "));
Serial.print(pulse_interval_ms);
Serial.print(F(" "));
//5 mode
EEPROM.get( (4*sizeof(float)), m5_switch_interval);
if (m5_switch_interval < MIN_SWITCH_INTERVAl) { m5_switch_interval = MIN_SWITCH_INTERVAl; }
if (m5_switch_interval > MAX_SWITCH_INTERVAl) { m5_switch_interval = MAX_SWITCH_INTERVAl; }
//m5_switch_interval = ; // 3
EEPROM.get( (5*sizeof(float)), br_button_5);
if ( (br_button_5 < MIN_BRIGHTNESS_5_MODE) || (br_button_5 > MAX_BRIGHTNESS_5_MODE) ) { br_button_5 = 127; }
//br_button = ;
Serial.print(F("5: "));
Serial.print(m5_switch_interval);
Serial.print(F(" "));
Serial.println(br_button_5);
}
void prepare_vals_for_new_mode()
{
switch ( current_mode )
{
case 1: // bright all
FastLED.setTemperature( SELECT_TEMPERATURE );
//memset8( leds, 255, NUM_LEDS * sizeof(CRGB) );
for (n = 0; n < NUM_LEDS; n++)
{
leds[n] = CRGB::White;
}
//br_button = 127;
FastLED.setBrightness(br_button); // 0 .. 255
FastLED.show();
n = 0;
delay(1000);
break;
case 2: //mic sound level
FastLED.setTemperature( SELECT_TEMPERATURE );
for(n_sect = 0; n_sect < NUNMBER_SECTORS; n_sect++)
{
for (n = n_led_segments[n_sect][0]; n <= n_led_segments[n_sect][1]; n++) // + 1
{
if ( n_sect == white_sector_2 )
{
leds[n] = CRGB(segments_colors_2[n_sect + 1], segments_colors_2[n_sect + 1], segments_colors_2[n_sect + 1]);
} else {
leds[n] = CHSV(segments_colors_2[n_sect + 1], 255, br_button_2); //or random saturation
}
}
}
FastLED.setBrightness(br_button_2);
//delay(1);
n = 0;
FastLED.show();
delay(1000);
break;
case 3: //serial all
FastLED.setTemperature( SELECT_TEMPERATURE );
//memset8( leds, 255, NUM_LEDS * sizeof(CRGB) );
for (n = 0; n < NUM_LEDS; n++)
{
leds[n] = CRGB::Black;
}
FastLED.setBrightness(br_button_3); //127
FastLED.show();
delay(1000);
timer_3_2 = millis();
n = 0;
turn_on_way = true;
break;
case 4: //pulse
FastLED.setTemperature( SELECT_TEMPERATURE );
//memset8( leds, 255, NUM_LEDS * sizeof(CRGB) );
FastLED.setBrightness(MAX_BRIGHTNESS_4_MODE);
FastLED.show();
delay(100);
for (n = 0; n < NUM_LEDS; n++)
{
//leds[n] = CRGB::White;
leds[n] = CRGB(MAX_BRIGHTNESS_4_MODE, MAX_BRIGHTNESS_4_MODE, MAX_BRIGHTNESS_4_MODE);
}
//FastLED.setBrightness(0);
br_pulse = MAX_BRIGHTNESS_4_MODE; //0 127
//FastLED.setBrightness(br_pulse);
FastLED.show();
delay(1000);
n = 0;
turn_on_way = true;
break;
case 5: //segments on off
FastLED.setTemperature( SELECT_TEMPERATURE );
memset8( leds, 0, NUM_LEDS * sizeof(CRGB) );
for (n = 0; n < NUM_LEDS; n++)
{
leds[n] = CRGB::Black;
//leds[n] = CRGB(MIN_BRIGHTNESS_5_MODE, MIN_BRIGHTNESS_5_MODE, MIN_BRIGHTNESS_5_MODE);
}
//FastLED.setBrightness(255);
FastLED.setBrightness(br_button_5);
FastLED.show();
delay(1000);
n_sect = 0;
turn_on_way = true;
break;
case 6: //light music white
FastLED.setTemperature( SELECT_TEMPERATURE );
//memset8( leds, 0, NUM_LEDS * sizeof(CRGB) );
for (n = 0; n < NUM_LEDS; n++)
{
leds[n] = CRGB::Black;
}
FastLED.setBrightness(127);
FastLED.show();
delay(1000);
n = 0;
FastLED.setBrightness(MAX_BRIGHTNESS);
break;
case 7: //light music color
FastLED.setTemperature( SELECT_TEMPERATURE );
memset8( leds, 0, NUM_LEDS * sizeof(CRGB) );
for (n = 0; n < NUM_LEDS; n++)
{
leds[n] = CRGB::Black;
}
FastLED.setBrightness(127);
FastLED.show();
delay(1000);
n = 0;
FastLED.setBrightness(MAX_BRIGHTNESS);
break;
}
}
void loop() {
//buttons remote control
if (irrecv.decode(&results)) {
code_command = results.value;
irrecv.resume();
#ifdef RC1 //arrows top RC
switch (code_command)
{
case 0xFFA25D:
current_mode = 1;
Serial.println("Mode 1");
prepare_vals_for_new_mode();
break;
case 0xFF629D:
current_mode = 2;
Serial.println("Mode 2");
prepare_vals_for_new_mode();
break;
case 0xFFE21D:
//current_mode = 3; //
//Serial.println("Mode 3"); //
break;
case 0xFF22DD:
//current_mode = 4; //
//Serial.println("Mode 4"); //
break;
case 0xFF02FD:
current_mode = 5;
Serial.println("Mode 5");
prepare_vals_for_new_mode();
break;
case 0xFFC23D:
current_mode = 6;
Serial.println("Mode 6");
prepare_vals_for_new_mode();
break;
case 0xFFE01F:
current_mode = 7;
Serial.println("Mode 7");
prepare_vals_for_new_mode();
break;
case 0xFFA857:
//Serial.println("8");
break;
case 0xFF906F:
//Serial.println("9");
break;
case 0xFF6897:
//Serial.println("*");
bright_button_minus = true;
break;
case 0xFF9867:
//Serial.println("0");
break;
case 0xFFB04F:
//Serial.println("#");
bright_button_plus = true;
break;
case 0xFF18E7: //
br_button_plus = true;
//Serial.println("Up");
break;
case 0xFF10EF:
current_mode--;
if (current_mode == 4) {current_mode = 3;} //
if (current_mode < 1) { current_mode = NUNMBER_MODES; }
if (current_mode > NUNMBER_MODES) { current_mode = 1; }
Serial.print(current_mode);
Serial.println(" mode select");
//Serial.println("Left");
prepare_vals_for_new_mode();
break;
case 0xFF38C7:
Serial.println("Oк");
if (turn == true) //OFF
{
turn = false;
mem_mode = current_mode;
current_mode = 0; //109
FastLED.setBrightness(0);
FastLED.show();
delay(1000);
} else { //ON
turn = true;
//current_mode = 1;
//Serial.println("Mode 1");
current_mode = mem_mode;
Serial.print("Mode ");
Serial.println(current_mode);
prepare_vals_for_new_mode();
}
break;
case 0xFF5AA5:
current_mode++;
if (current_mode == 4) {current_mode = 5;} //
if (current_mode > NUNMBER_MODES) { current_mode = 1; }
if (current_mode < 1) { current_mode = NUNMBER_MODES; }
Serial.print(current_mode);
Serial.println(" mode select");
//Serial.println("Right");
prepare_vals_for_new_mode();
break;
case 0xFF4AB5:
br_button_minus = true;
//Serial.println("Down");
break;
}
#else //arrows bottom RC
switch (code_command)
{
case 0xFF629D:
br_button_plus = true;
Serial.println("Up");
break;
case 0xFF22DD:
current_mode--;
if (current_mode == 4) {current_mode = 3;} //
if (current_mode < 1) { current_mode = NUNMBER_MODES; }
if (current_mode > NUNMBER_MODES) { current_mode = 1; }
Serial.print(current_mode);
Serial.println(" mode select");
//Serial.println("Left");
prepare_vals_for_new_mode();
break;
case 0xFF02FD:
Serial.println("Ok");
if (turn == true) //OFF
{
turn = false;
mem_mode = current_mode;
current_mode = 0; //109
FastLED.setBrightness(0);
FastLED.show();
delay(1000);
} else { //ON
turn = true;
//current_mode = 1;
//Serial.println("Mode 1");
current_mode = mem_mode;
Serial.print("Mode ");
Serial.println(current_mode);
prepare_vals_for_new_mode();
}
break;
case 0xFFC23D:
current_mode++;
if (current_mode == 4) {current_mode = 5;} //
if (current_mode > NUNMBER_MODES) { current_mode = 1; }
if (current_mode < 1) { current_mode = NUNMBER_MODES; }
Serial.print(current_mode);
Serial.println(" mode select");
//Serial.println("Right");
prepare_vals_for_new_mode();
break;
case 0xFFA857:
br_button_minus = true;
Serial.println("Down");
break;
case 0xFF6897:
current_mode = 1;
Serial.println("Mode 1");
prepare_vals_for_new_mode();
break;
case 0xFF9867:
current_mode = 2;
Serial.println("2");
prepare_vals_for_new_mode();
break;
case 0xFFB04F:
//current_mode = 3;
//Serial.println("3");
break;
case 0xFF30CF:
//current_mode = 4;
//Serial.println("4");
break;
case 0xFF18E7:
current_mode = 5;
Serial.println("5");
prepare_vals_for_new_mode();
break;
case 0xFF7A85:
current_mode = 6;
Serial.println("6");
prepare_vals_for_new_mode();
break;
case 0xFF10EF:
current_mode = 7;
Serial.println("7");
prepare_vals_for_new_mode();
break;
case 0xFF38C7:
//Serial.println("8");
break;
case 0xFF5AA5:
//Serial.println("9");
break;
case 0xFF42BD:
//Serial.println("*");
bright_button_minus = true;
break;
case 0xFF4AB5:
//Serial.println("0");
break;
case 0xFF52AD:
//Serial.println("#");
bright_button_plus = true;
break;
}
#endif
}
if ( millis() > (timer_cm + CHANGE_INTERVAL_SELECT_BUTTON) )
{
timer_cm = millis();
if (digitalRead(CHANGE_MODE_PIN)) {
current_mode++;
if (current_mode > NUNMBER_MODES) { current_mode = 1; }
if (current_mode < 1) { current_mode = NUNMBER_MODES; }
Serial.print(current_mode);
Serial.println(F(" mode select"));
prepare_vals_for_new_mode();
}
}
switch ( current_mode ) //переключение в любой момент
{
case 1: //button increase and decrease brightness
//Serial.println("1 mode select");
if ( millis() > (timer_1 + CHANGE_INTERVAL) )
{
timer_1 = millis();
if (digitalRead(INCREASE_PIN) || (br_button_plus == true) || (bright_button_plus == true) ) {
if (br_button < MAX_BRIGHTNESS_1_MODE) {
//br_button++;
br_button += BR_STEP_1_MODE;
EEPROM.put( (6*sizeof(float)), br_button);
Serial.print(F("EEPROM update 1 bright: "));
Serial.println(br_button);
if (br_button > MAX_BRIGHTNESS_1_MODE) { br_button = MAX_BRIGHTNESS_1_MODE; }
Serial.print(F("Brightness: "));
Serial.println(br_button);
FastLED.setBrightness(br_button);
FastLED.setTemperature( SELECT_TEMPERATURE );
FastLED.show();
//delay(CHANGE_INTERVAL);
}
br_button_plus = false;
bright_button_plus = false;
} else if (digitalRead(DECREASE_PIN) || (br_button_minus == true) || (bright_button_minus == true)) {
if (br_button > MIN_BRIGHTNESS_1_MODE) {
//br_button--;
br_button -= BR_STEP_1_MODE;
EEPROM.put( (6*sizeof(float)), br_button);
Serial.print(F("EEPROM update 1 bright: "));
Serial.println(br_button);
if (br_button < MIN_BRIGHTNESS_1_MODE) { br_button = MIN_BRIGHTNESS_1_MODE; }
Serial.print(F("Brightness: "));
Serial.println(br_button);
FastLED.setBrightness(br_button); //or apply after button turn off pause
FastLED.setTemperature( SELECT_TEMPERATURE );
FastLED.show();
//delay(CHANGE_INTERVAL);
}
br_button_minus = false;
bright_button_minus = false;
} else { //all buttons off
}
}
break;
case 2:
if ( millis() > (timer_2_1 + CHANGE_INTERVAL) )
{
timer_2_1 = millis();
//pulse interval change
if ( digitalRead(INCREASE_PIN) || (br_button_plus == true) ) //select color x10
{
if ( (segments_colors[selected_segment_2] + COLOR_STEP_2_MODE) <= MAX_COLOR) { //10
segments_colors_2[selected_segment_2] += COLOR_STEP_2_MODE; //1 2 3 5 10 25
} else {
segments_colors_2[selected_segment_2] = 0;
}
Serial.print(F("Segment: "));
Serial.print(String(selected_segment_2));
Serial.print(F(" Color: "));
Serial.println(String(segments_colors_2[selected_segment_2]));
EEPROM.put( ( ( 5 + selected_segment_2 )*sizeof(float)), segments_colors_2[selected_segment_2]);
Serial.print(F("EEPROM update segment "));
Serial.print(selected_segment_2);
Serial.print(F(" color: "));
Serial.println(segments_colors_2[selected_segment_2]);
for (n = n_led_segments[selected_segment_2 - 1][0]; n <= n_led_segments[selected_segment_2 - 1][1]; n++)
{
if ( (n >= n_led_segments[white_sector_2][0]) && (n <= n_led_segments[white_sector_2][1]) )
{
leds[n] = CRGB(segments_colors_2[selected_segment_2], segments_colors_2[selected_segment_2], segments_colors_2[selected_segment_2]);
} else {
leds[n] = CHSV(segments_colors_2[selected_segment_2], 255, br_button_2); //or random saturation
}
//Serial.println(String(n_sect) + " " + String(n) + " " + String(br_freq[xres - 1 - i]));
}
FastLED.setBrightness(br_button_2);
FastLED.setTemperature( SELECT_TEMPERATURE );
FastLED.show();
delay(100);
br_button_plus = false;
} else if (bright_button_plus == true) {
if (br_button_2 < MAX_BRIGHTNESS) {
//br_button_2++;
br_button_2 += BR_STEP_2_MODE; //25 10 5 1
if (br_button_2 > MAX_BRIGHTNESS) { br_button_2 = MAX_BRIGHTNESS; }
Serial.print(F("Brightness: "));
Serial.println(br_button_2);
EEPROM.put( (3*sizeof(float)), br_button_2);
Serial.print(F("EEPROM update 2 bright: "));
Serial.println(br_button_2);
for(n_sect = 0; n_sect < NUNMBER_SECTORS; n_sect++)
{
for (n = n_led_segments[n_sect][0]; n <= n_led_segments[n_sect][1]; n++) // + 1
{
if ( (n >= n_led_segments[white_sector_2][0]) && (n <= n_led_segments[white_sector_2][1]) )
{
segments_colors_2[n_sect + 1] = br_button_2;
leds[n] = CRGB(segments_colors_2[n_sect + 1], segments_colors_2[n_sect + 1], segments_colors_2[n_sect + 1]);
} else {
leds[n] = CHSV(segments_colors_2[n_sect + 1], 255, br_button_2); //or random saturation
}
}
}
//FastLED.setBrightness(br_button_2);
FastLED.setTemperature( SELECT_TEMPERATURE );
FastLED.show();
delay(100);
//EEPROM.put( (1*sizeof(float)), br_button_2);
//Serial.print(F("EEPROM update 2 bright: "));
//Serial.println(br_button_2);
//delay(CHANGE_INTERVAL);
}
bright_button_plus = false;
} else if (bright_button_minus == true) {
if (br_button_2 > MIN_BRIGHTNESS_2_MODE) {
//br_button_2--;
br_button_2 -= BR_STEP_2_MODE; //1 5 10 25
if (br_button_2 < MIN_BRIGHTNESS_2_MODE) { br_button_2 = MIN_BRIGHTNESS_2_MODE; }
Serial.print(F("Brightness: "));
Serial.println(br_button_2);
/*EEPROM.put( (3*sizeof(float)), br_button_2);
Serial.print(F("EEPROM update 2 bright: "));
Serial.println(br_button_2);*/
for(n_sect = 0; n_sect < NUNMBER_SECTORS; n_sect++)
{
for (n = n_led_segments[n_sect][0]; n <= n_led_segments[n_sect][1]; n++) // + 1
{
if ( (n >= n_led_segments[white_sector_2][0]) && (n <= n_led_segments[white_sector_2][1]) )
{
segments_colors_2[n_sect + 1] = br_button_2;
leds[n] = CRGB(segments_colors_2[n_sect + 1], segments_colors_2[n_sect + 1], segments_colors_2[n_sect + 1]);
} else {
leds[n] = CHSV(segments_colors_2[n_sect + 1], 255, br_button_2); //or random saturation 255
}
}
}
FastLED.setTemperature( SELECT_TEMPERATURE );
FastLED.show();
EEPROM.put( (3*sizeof(float)), br_button_2);
Serial.print(F("EEPROM update 2 bright: "));
Serial.println(br_button_2);
delay(100);
//delay(CHANGE_INTERVAL);
}
bright_button_minus = false;
}
}
if ( millis() > (timer_2_2 + CHANGE_INTERVAL_SELECT_BUTTON) )
{
timer_2_2 = millis();
if ( digitalRead(DECREASE_PIN) || (br_button_minus == true) ) { //select segment
selected_segment_2 += 1;
if (selected_segment_2 > NUNMBER_SECTORS) {
selected_segment_2 = 1;
}
Serial.println();
Serial.print(F("Segment: "));
Serial.println(String(selected_segment_2));
for (seg = 1; seg <= NUNMBER_SECTORS; seg++)
{
Serial.print(F("Segment: "));
Serial.print(String(seg));
Serial.print(F(" color: "));
Serial.println(String(segments_colors[seg]));
}
br_button_minus = false;
}
}
break;
case 3: //serial switch on all LEDs
if ( millis() > (timer_3 + CHANGE_INTERVAL) )
{
timer_3 = millis();
//serial interval turn on
if (digitalRead(INCREASE_PIN) || (br_button_plus == true) ) {
if (serial_on_interval < MAX_SERIAL_ON_INTERVAL) {
serial_on_interval++;
if (serial_on_interval > MAX_SERIAL_ON_INTERVAL) { serial_on_interval = MAX_SERIAL_ON_INTERVAL; }
Serial.print(F("Serial On interval: "));
Serial.println(String(serial_on_interval) + " ms");
EEPROM.put( (0*sizeof(float)), serial_on_interval); //eeAddress, f put
Serial.print("EEPROM update 3 time: ");
Serial.println(serial_on_interval);
//delay(CHANGE_INTERVAL);
}
br_button_plus = false;
} else if (digitalRead(DECREASE_PIN) || (br_button_minus == true) ) {
if (serial_on_interval > MIN_SERIAL_ON_INTERVAL) {
serial_on_interval--;
if (serial_on_interval < MIN_SERIAL_ON_INTERVAL) { serial_on_interval = MIN_SERIAL_ON_INTERVAL; }
Serial.print(F("Serial On interval: "));
Serial.println(String(serial_on_interval) + " ms");
EEPROM.put( (0*sizeof(float)), serial_on_interval); //eeAddress, f
Serial.print(F("EEPROM update 3 time: "));
Serial.println(serial_on_interval);
//delay(CHANGE_INTERVAL);