-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShelfClock.ino
3782 lines (3420 loc) · 210 KB
/
ShelfClock.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 <NonBlockingRtttl.h>
#include<MegunoLink.h>
#include <FastLED.h>
#include <WiFi.h>
#include "WebServer.h"
#include <FS.h>
#include <HTTPUpdateServer.h>
#include "DHT.h"
#include <Preferences.h>
#include <ESPmDNS.h>
#include <Update.h>
#include "RTClib.h"
#include <AutoConnect.h>
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define SEGMENTS_PER_NUMBER 7 // this can never change unless you redesign all display routines
#define NUMBER_OF_DIGITS 7 // 7 = 4 real + 3 fake, this should be always 7 unless you redesign all display routines
#define SPECTRUM_PIXELS 37 // 7 digits = 37 (5 unshared segments for every digit (7) and 2 more on the last from the side)
#define DHTTYPE DHT11 // DHT 11 tempsensor
#define MIC_IN_PIN 34 // Use 34 for mic input
#define AUDIO_GATE_PIN 15 // for sound gate input trigger
#define BUZZER_PIN 16 // peizo speaker
#define DHT_PIN 18 // temp sensor pin
#define LED_PIN 2 // led control pin
#define PHOTORESISTER_PIN 36 // select the analog input pin for the photoresistor
#define MILLI_AMPS 2400
#define LEDS_PER_SEGMENT 7 // can be 1 to 10 LEDS per segment
#define LEDS_PER_DIGIT (LEDS_PER_SEGMENT * SEGMENTS_PER_NUMBER)
#define FAKE_NUM_LEDS (NUMBER_OF_DIGITS * LEDS_PER_DIGIT)
#define PHOTO_SAMPLES 15 //number of samples to take from the photoresister
#define SEGMENTS_LEDS (SPECTRUM_PIXELS * LEDS_PER_SEGMENT) // Number leds in all segments
#define SPOT_LEDS (NUMBER_OF_DIGITS * 2) // Number of Spotlight leds
#define NUM_LEDS (SEGMENTS_LEDS + SPOT_LEDS) // Number of all leds
#if LEDS_PER_SEGMENT == 1
#define seg(n) n*LEDS_PER_SEGMENT
#elif LEDS_PER_SEGMENT == 2
#define seg(n) n*LEDS_PER_SEGMENT, n*LEDS_PER_SEGMENT+1
#elif LEDS_PER_SEGMENT == 3
#define seg(n) n*LEDS_PER_SEGMENT, n*LEDS_PER_SEGMENT+1, n*LEDS_PER_SEGMENT+2
#elif LEDS_PER_SEGMENT == 4
#define seg(n) n*LEDS_PER_SEGMENT, n*LEDS_PER_SEGMENT+1, n*LEDS_PER_SEGMENT+2, n*LEDS_PER_SEGMENT+3
#elif LEDS_PER_SEGMENT == 5
#define seg(n) n*LEDS_PER_SEGMENT, n*LEDS_PER_SEGMENT+1, n*LEDS_PER_SEGMENT+2, n*LEDS_PER_SEGMENT+3, n*LEDS_PER_SEGMENT+4
#elif LEDS_PER_SEGMENT == 6
#define seg(n) n*LEDS_PER_SEGMENT, n*LEDS_PER_SEGMENT+1, n*LEDS_PER_SEGMENT+2, n*LEDS_PER_SEGMENT+3, n*LEDS_PER_SEGMENT+4, n*LEDS_PER_SEGMENT+5
#elif LEDS_PER_SEGMENT == 7
#define seg(n) n*LEDS_PER_SEGMENT, n*LEDS_PER_SEGMENT+1, n*LEDS_PER_SEGMENT+2, n*LEDS_PER_SEGMENT+3, n*LEDS_PER_SEGMENT+4, n*LEDS_PER_SEGMENT+5, n*LEDS_PER_SEGMENT+6
#elif LEDS_PER_SEGMENT == 8
#define seg(n) n*LEDS_PER_SEGMENT, n*LEDS_PER_SEGMENT+1, n*LEDS_PER_SEGMENT+2, n*LEDS_PER_SEGMENT+3, n*LEDS_PER_SEGMENT+4, n*LEDS_PER_SEGMENT+5, n*LEDS_PER_SEGMENT+6, n*LEDS_PER_SEGMENT+7
#elif LEDS_PER_SEGMENT == 9
#define seg(n) n*LEDS_PER_SEGMENT, n*LEDS_PER_SEGMENT+1, n*LEDS_PER_SEGMENT+2, n*LEDS_PER_SEGMENT+3, n*LEDS_PER_SEGMENT+4, n*LEDS_PER_SEGMENT+5, n*LEDS_PER_SEGMENT+6, n*LEDS_PER_SEGMENT+7, n*LEDS_PER_SEGMENT+8
#elif LEDS_PER_SEGMENT == 10
#define seg(n) n*LEDS_PER_SEGMENT, n*LEDS_PER_SEGMENT+1, n*LEDS_PER_SEGMENT+2, n*LEDS_PER_SEGMENT+3, n*LEDS_PER_SEGMENT+4, n*LEDS_PER_SEGMENT+5, n*LEDS_PER_SEGMENT+6, n*LEDS_PER_SEGMENT+7, n*LEDS_PER_SEGMENT+8, n*LEDS_PER_SEGMENT+9
#else
#error "Not supported Leds per segment. You need to add definition of seg(n) with needed number of elements according to formula above"
#endif
#define digit0 seg(0), seg(1), seg(2), seg(3), seg(4), seg(5), seg(6)
#define fdigit1 seg(2), seg(7), seg(10), seg(15), seg(8), seg(3), seg(9)
#define digit2 seg(10), seg(11), seg(12), seg(13), seg(14), seg(15), seg(16)
#define fdigit3 seg(12), seg(17), seg(20), seg(25), seg(18), seg(13), seg(19)
#define digit4 seg(20), seg(21), seg(22), seg(23), seg(24), seg(25), seg(26)
#define fdigit5 seg(22), seg(27), seg(30), seg(35), seg(28), seg(23), seg(29)
#define digit6 seg(30), seg(31), seg(32), seg(33), seg(34), seg(35), seg(36)
const char* host = "shelfclock";
const int daylightOffset_sec = 3600;
const char* ntpServer = "pool.ntp.org";
int breakOutSet = 0; //jump out of count
int colorWheelPosition = 255; // COLOR WHEEL POSITION
int colorWheelPositionTwo = 255; // 2nd COLOR WHEEL POSITION
int decay = 0; // HOW MANY MS BEFORE ONE LIGHT DECAY
int decay_check = 0;
long pre_react = 0; // NEW SPIKE CONVERSION
long react = 0; // NUMBER OF LEDs BEING LIT
long post_react = 0; // OLD SPIKE CONVERSION
const int colorWheelSpeed = 3;
int sleepTimerCurrent = 0;
int isAsleep = 0;
int photoresisterReadings[PHOTO_SAMPLES]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int lightSensorValue = 255;
int previousTimeMin = 0;
int previousTimeHour = 0;
int previousTimeDay = 0;
int previousTimeWeek = 0;
int previousTimeMonth = 0;
byte randomMinPassed = 1;
byte randomHourPassed = 1;
byte randomDayPassed = 1;
byte randomWeekPassed = 1;
byte randomMonthPassed = 1;
bool dotsOn = true;
unsigned long prevTime = 0;
unsigned long prevTime2 = 0;
unsigned long countdownMilliSeconds;
unsigned long endCountDownMillis;
byte fakeclockrunning = 0;
unsigned long countupMilliSeconds;
unsigned long CountUpMillis;
int scoreboardLeft = 0;
int scoreboardRight = 0;
int currentMode = 0;
int currentReal = 0;
int cylonPosition = 0;
int clearOldLeds = 0;
byte rain[SPECTRUM_PIXELS];
byte greenMatrix[SPECTRUM_PIXELS];
int lightshowSpeed = 1;
int snakeLastDirection = 0; //snake's last dirction
int snakePosition = 0; //snake's position
int foodSpot = random(SPECTRUM_PIXELS-1); //food spot
int snakeWaiting = 0; //waiting
int getSlower = 180;
int daysUptime = 0;
int averageAudioInput = 0;
struct tm timeinfo;
CRGB LEDs[NUM_LEDS];
Preferences preferences;
DHT dht(DHT_PIN, DHTTYPE);
WebServer server(80);
HTTPUpdateServer httpUpdateServer;
RTC_DS3231 rtc;
AutoConnect Portal(server);
AutoConnectConfig Config;
// global settings that get saved to flash via preffs
byte cd_r_val = 0;
byte cd_g_val = 255;
byte cd_b_val = 0;
byte r0_val = 255; //spotlight
byte g0_val = 255;
byte b0_val = 255;
byte r1_val = 255; //colorHour
byte g1_val = 0;
byte b1_val = 0;
byte r2_val = 255; //colorMins
byte g2_val = 0;
byte b2_val = 0;
byte r3_val = 255; //colorColon
byte g3_val = 0;
byte b3_val = 0;
byte r4_val = 255; //dayColor
byte g4_val = 0;
byte b4_val = 0;
byte r5_val = 255; //monthColor
byte g5_val = 0;
byte b5_val = 0;
byte r6_val = 255; //separatorColor
byte g6_val = 0;
byte b6_val = 0;
byte r7_val = 255; //TempColor
byte g7_val = 0;
byte b7_val = 0;
byte r8_val = 255; //TypeColor
byte g8_val = 0;
byte b8_val = 0;
byte r9_val = 255; //DegreeColor
byte g9_val = 0;
byte b9_val = 0;
byte r10_val = 255; //HumiColor
byte g10_val = 0;
byte b10_val = 0;
byte r11_val = 255; //SymbolColor
byte g11_val = 0;
byte b11_val = 0;
byte r12_val = 255; //HumiDecimalColor
byte g12_val = 0;
byte b12_val = 0;
byte r13_val = 255; //scoreboard left
byte g13_val = 0;
byte b13_val = 0;
byte r14_val = 255; //scoreboard right
byte g14_val = 0;
byte b14_val = 0;
byte r15_val = 255; //spectrum analyzer
byte g15_val = 0;
byte b15_val = 0;
byte r16_val = 255; //scrolling text analyzer
byte g16_val = 255;
byte b16_val = 255;
byte r17_val = 0; //spectrum analyzer background
byte g17_val = 0;
byte b17_val = 0;
byte clockMode = 0; // Clock modes: 0=Clock, 1=Countdown, 2=Temperature, 3=Scoreboard, 4=Stopwatch, 5=Lightshow, 6=Rainbows/Scroll, 7=Date, 8=Humidity, 9=Spectrum, 10=Display Off
byte clockDisplayType = 3; //0-Center Times, 1-24-hour Military Time, 2-12-hour Space-Padded, 3-Blinking Center Light
byte dateDisplayType = 5; //0-Zero-Padded (MMDD), 1-Space-Padded (MMDD), 2-Center Dates (1MDD), 3-Just Day of Week (Sun), 4-Just Numeric Day (DD), 5-With "." Separator (MM.DD), 6-Just Year (YYYY)
byte tempDisplayType = 0; //0-Temperature with Degree and Type (79°F), 1-Temperature with just Type (79 F), 2-Temperature with just Degree (79°), 3-Temperature with Decimal (79.9), 4-Just Temperature (79)
byte humiDisplayType = 0; //0-Humidity with Symbol (34 H), 1-Humidity with Decimal (34.9), 2-Just Humidity (79)
byte pastelColors = 0;
byte temperatureSymbol = 39; // 36=Celcius, 39=Fahrenheit check 'numbers'
bool DSTime = 0;
long gmtOffset_sec = -28800;
byte ClockColorSettings = 0;
byte DateColorSettings = 0;
byte tempColorSettings = 0;
byte humiColorSettings = 0;
int temperatureCorrection = 0;
int colonType = 0;
byte ColorChangeFrequency = 0;
byte brightness = 10; //set to 10 for photoresister control at startup
String scrollText = "dAdS ArE tHE bESt";
bool colorchangeCD = 1;
bool useAudibleAlarm = 0;
int spectrumMode = 0;
int spectrumColorSettings = 2;
int spectrumBackgroundSettings = 0;
int realtimeMode = 0;
int spotlightsColorSettings = 0;
bool useSpotlights = 1;
int scrollColorSettings = 0;
bool scrollOverride = 1;
bool scrollOptions1 = 0; //Military Time (HHMM)
bool scrollOptions2 = 0; //Day of Week (DOW)
bool scrollOptions3 = 0; //Today's Date (DD-MM)
bool scrollOptions4 = 0; //Year (YYYY)
bool scrollOptions5 = 0; //Temperature (70 °F)
bool scrollOptions6 = 0; //Humidity (47 H)
bool scrollOptions7 = 0; //Text Message
bool scrollOptions8 = 0; //IP Address of Clock
int scrollFrequency = 1;
int lightshowMode = 0;
byte randomSpectrumMode = 0;
int suspendFrequency = 1; //in minutes
byte suspendType = 0; //0-off, 1-digits-only, 2-everything
CRGB hourColor = CRGB(r1_val, g1_val, b1_val);
CRGB colonColor = CRGB(r3_val, g3_val, b3_val);
CRGB spotlightsColor = CRGB(r0_val, g0_val, b0_val);
CRGB alternateColor = CRGB::Black;
CRGB scrollColor = CRGB(r16_val, g16_val, b16_val);
CRGB spectrumColor = CRGB(r15_val, g15_val, b15_val);
CRGB spectrumBackground = CRGB(r17_val, g17_val, b17_val);
CRGB humiColor = CRGB(r10_val, g10_val, b10_val);
CRGB tinyhumiColor = CRGB(r10_val, g10_val, b10_val);
CRGB symbolColor = CRGB(r11_val, g11_val, b11_val);
CRGB humiDecimalColor = CRGB(r12_val, g12_val, b12_val);
CRGB tinytempColor = CRGB(r7_val, g7_val, b7_val);
CRGB tempColor = CRGB(r7_val, g7_val, b7_val);
CRGB typeColor = CRGB(r8_val, g8_val, b8_val);
CRGB degreeColor = CRGB(r9_val, g9_val, b9_val);
CRGB dayColor = CRGB(r4_val, g4_val, b4_val);
CRGB monthColor = CRGB(r5_val, g5_val, b5_val);
CRGB tinymonthColor = CRGB(r5_val, g5_val, b5_val);
CRGB separatorColor = CRGB(r6_val, g6_val, b6_val);
CRGB minColor = CRGB(r2_val, g2_val, b2_val);
CRGB tinyhourColor = CRGB(r3_val, g3_val, b3_val);
CRGB lightchaseColorOne = CRGB::Blue;
CRGB lightchaseColorTwo = CRGB::Red;
CRGB oldsnakecolor = CRGB::Green;
CRGB spotcolor = CHSV(random(0, 255), 255, 255);
const uint16_t FAKE_LEDs[FAKE_NUM_LEDS] = {digit0, fdigit1, digit2, fdigit3, digit4, fdigit5, digit6};
//fake LED layout for spectrum (from the middle out)
const uint16_t FAKE_LEDs_C_BMUP[SEGMENTS_LEDS] = {seg(17), seg(11), seg(21), seg(12), seg(20), seg(19), seg(27), seg(7), seg(22), seg(10), seg(26), seg(16), seg(25), seg(13), seg(18), seg(1), seg(31), seg(2), seg(30), seg(9), seg(29), seg(15), seg(23), seg(14), seg(24), seg(0), seg(32), seg(6), seg(36), seg(3), seg(35), seg(8), seg(28), seg(5), seg(33), seg(4), seg(34)};
//fake LED layout for spectrum (bfrom the outside in)
const uint16_t FAKE_LEDs_C_CMOT[SEGMENTS_LEDS] = {seg(19), seg(26), seg(16), seg(20), seg(13), seg(25), seg(12), seg(17), seg(18), seg(21), seg(14), seg(24), seg(11), seg(29), seg(9), seg(22), seg(15), seg(23), seg(10), seg(28), seg(7), seg(27), seg(8), seg(36), seg(6), seg(30), seg(3), seg(35), seg(2), seg(34), seg(1), seg(31), seg(4), seg(32), seg(5), seg(33), seg(0)};
//fake LED layout for spectrum (bottom-left to right-top)
const uint16_t FAKE_LEDs_C_BLTR[SEGMENTS_LEDS] = {seg(32), seg(31), seg(27), seg(30), seg(36), seg(33), seg(34), seg(35), seg(29), seg(22), seg(21), seg(17), seg(20), seg(26), seg(23), seg(28), seg(24), seg(25), seg(19), seg(12), seg(11), seg(7), seg(10), seg(16), seg(13), seg(18), seg(14), seg(15), seg(9), seg(2), seg(1), seg(0), seg(6), seg(3), seg(8), seg(4), seg(5)};
//fake LED layout for spectrum (top-left to bottom-right)
const uint16_t FAKE_LEDs_C_TLBR[SEGMENTS_LEDS] = {seg(34), seg(33), seg(32), seg(36), seg(35), seg(28), seg(24), seg(23), seg(29), seg(30), seg(31), seg(27), seg(22), seg(26), seg(25), seg(18), seg(14), seg(13), seg(19), seg(20), seg(21), seg(17), seg(12), seg(16), seg(15), seg(8), seg(4), seg(3), seg(9), seg(10), seg(11), seg(7), seg(2), seg(6), seg(5), seg(0), seg(1)};
//fake LED layout for spectrum (top-middle down)
const uint16_t FAKE_LEDs_C_TMDN[SEGMENTS_LEDS] = {seg(18), seg(14), seg(24), seg(13), seg(25), seg(19), seg(8), seg(28), seg(15), seg(23), seg(16), seg(26), seg(12), seg(20), seg(17), seg(4), seg(34), seg(3), seg(35), seg(9), seg(29), seg(10), seg(22), seg(11), seg(21), seg(5), seg(33), seg(6), seg(36), seg(2), seg(30), seg(7), seg(27), seg(0), seg(32), seg(1), seg(31)};
//fake LED layout for spectrum (center-sides in)
const uint16_t FAKE_LEDs_C_CSIN[SEGMENTS_LEDS] = {seg(5), seg(32), seg(0), seg(33), seg(6), seg(36), seg(4), seg(31), seg(1), seg(34), seg(3), seg(30), seg(2), seg(35), seg(9), seg(29), seg(8), seg(27), seg(7), seg(28), seg(15), seg(22), seg(10), seg(23), seg(16), seg(26), seg(14), seg(21), seg(11), seg(24), seg(13), seg(20), seg(12), seg(25), seg(19), seg(18), seg(17)};
//fake LED layout for spectrum (bottom-right to left-top)
const uint16_t FAKE_LEDs_C_BRTL[SEGMENTS_LEDS] = {seg(0), seg(1), seg(7), seg(2), seg(6), seg(5), seg(4), seg(3), seg(9), seg(10), seg(11), seg(17), seg(12), seg(16), seg(15), seg(8), seg(14), seg(13), seg(19), seg(20), seg(21), seg(27), seg(22), seg(26), seg(25), seg(18), seg(24), seg(23), seg(29), seg(30), seg(31), seg(32), seg(36), seg(35), seg(28), seg(34), seg(33)};
//fake LED layout for spectrum (top-right to bottom-left)
const uint16_t FAKE_LEDs_C_TRBL[SEGMENTS_LEDS] = {seg(4), seg(5), seg(0), seg(6), seg(3), seg(8), seg(14), seg(15), seg(9), seg(2), seg(1), seg(7), seg(10), seg(16), seg(13), seg(18), seg(24), seg(25), seg(19), seg(12), seg(11), seg(17), seg(20), seg(26), seg(23), seg(28), seg(34), seg(35), seg(29), seg(22), seg(21), seg(27), seg(30), seg(36), seg(33), seg(32), seg(31)};
//fake LED layout for spectrum (horizontal parts)
const uint16_t FAKE_LEDs_C_OUTS[SEGMENTS_LEDS] = {seg(31), seg(39), seg(36), seg(39), seg(34), seg(39), seg(27), seg(39), seg(29), seg(39), seg(28), seg(39), seg(21), seg(39), seg(26), seg(39), seg(24), seg(39), seg(17), seg(39), seg(19), seg(39), seg(18), seg(39), seg(11), seg(39), seg(16), seg(39), seg(14), seg(39), seg(7), seg(39),seg(9), seg(8), seg(1), seg(6), seg(4)};
const uint16_t FAKE_LEDs_C_OUTS2[SEGMENTS_LEDS] = {seg(1), seg(39), seg(6), seg(39), seg(4), seg(39), seg(7), seg(39), seg(9), seg(39), seg(8), seg(39), seg(11), seg(39), seg(16), seg(39), seg(14), seg(39), seg(17), seg(39), seg(19), seg(39), seg(18), seg(39), seg(21), seg(39), seg(26), seg(39), seg(24), seg(39), seg(27), seg(39),seg(29), seg(28), seg(31), seg(36), seg(34)};
//fake LED layout for spectrum (vertical parts)
const uint16_t FAKE_LEDs_C_VERT[SEGMENTS_LEDS] = {seg(32), seg(39), seg(33), seg(39), seg(30), seg(39), seg(35), seg(39), seg(39), seg(22), seg(39), seg(23), seg(39), seg(39), seg(20), seg(39), seg(25), seg(39), seg(39), seg(12), seg(39), seg(13), seg(39), seg(39), seg(10), seg(39), seg(15), seg(39), seg(39), seg(2), seg(39), seg(3), seg(39), seg(0), seg(39), seg(5), seg(39)};
const uint16_t FAKE_LEDs_C_VERT2[SEGMENTS_LEDS] = {seg(0), seg(39), seg(5), seg(39), seg(39), seg(2), seg(39), seg(3), seg(39), seg(39), seg(10), seg(39), seg(15), seg(39), seg(39), seg(12), seg(39), seg(13), seg(39), seg(39), seg(20), seg(39), seg(25), seg(39), seg(39), seg(22), seg(39), seg(23), seg(39), seg(30), seg(39), seg(35), seg(39), seg(32), seg(39), seg(33), seg(39)};
//fake LED layout for fire display
const uint16_t FAKE_LEDs_C_FIRE[SEGMENTS_LEDS] = {seg(17), seg(11), seg(21), seg(12), seg(20), seg(19), seg(27), seg(7), seg(22), seg(10), seg(26), seg(16), seg(25), seg(13), seg(18), seg(1), seg(31), seg(2), seg(30), seg(9), seg(29), seg(15), seg(23), seg(14), seg(24), seg(0), seg(32), seg(6), seg(36), seg(3), seg(35), seg(8), seg(28), seg(5), seg(33), seg(4), seg(34)};
//fake LED layout for Rain display
const uint16_t FAKE_LEDs_C_RAIN[SEGMENTS_LEDS] = {seg(30), seg(35), seg(1), seg(6), seg(4), seg(22), seg(23), seg(31), seg(36), seg(34), seg(12), seg(13), seg(7), seg(9), seg(8), seg(0), seg(5), seg(17), seg(19), seg(18), seg(10), seg(15), seg(21), seg(26), seg(24), seg(2), seg(3), seg(27), seg(29), seg(28), seg(20), seg(25), seg(11), seg(16), seg(14), seg(32), seg(33)};
//fake LED layout for Snake display
const uint16_t FAKE_LEDs_SNAKE[SEGMENTS_LEDS] = {seg(0), seg(1), seg(7), seg(2), seg(6), seg(5), seg(4), seg(3), seg(9), seg(10), seg(11), seg(17), seg(12), seg(16), seg(15), seg(8), seg(14), seg(13), seg(19), seg(20), seg(21), seg(27), seg(22), seg(26), seg(25), seg(18), seg(24), seg(23), seg(29), seg(30), seg(31), seg(32), seg(36), seg(35), seg(28), seg(34), seg(33)};
const char * rickroll2 = "Together:d=8,o=5,b=225:4d#,f.,c#.,c.6,4a#.,4g.,f.,d#.,c.,4a#,2g#,4d#,f.,c#.,c.6,2a#,g.,f.,1d#.,d#.,4f,c#.,c.6,2a#,4g.,4f,d#.,f.,g.,4g#.,g#.,4a#,c.6,4c#6,4c6,4a#,4g.,4g#,4a#,2g#";
const char * auldlang = "AuldLang:d=4,o=6,b=125:a5,d.,8d,d,f#,e.,8d,e,8f#,8e,d.,8d,f#,a,2b.,b,a.,8f#,f#,d,e.,8d,e,8f#,8e,d.,8b5,b5,a5,2d,16p";
const char * startrek = "Star Trek:d=4,o=5,b=63:8f.,16a#,d#.6,8d6,16a#.,16g.,16c.6,f6";
const char * starwars = "StarWars:d=4,o=5,b=250:8a,8p,8d6,8p,8a,8p,8d6,8p,8a,8d6,8p,8a,8p,8g#,a,8a,8g#,8a,g,8f#,8g,8f#,f.,8d.,16p,p.,8a,8p,8d6,8p,8a,8p,8d6,8p,8a,8d6,8p,8a,8p,8g#,8a,8p,8g,8p,g.,8f#,8g,8p,8c6,a#,a,g";
const char * birthday = "HappyBir:d=8,o=5,b=100:16c,16c,d,c,f,e.,16p,16c,16c,d,c,g,f.,16p,16c,16c,c6,a,f,e,d.,16p,16a#,16a#,a,f,g,f.";
const char * rickroll = "Never Gonna:d=4,o=5,b=200:8g,8a,8c6,8a,e6,8p,e6,8p,d6.,p,8p,8g,8a,8c6,8a,d6,8p,d6,8p,c6,8b,a.,8g,8a,8c6,8a,2c6,d6,b,a,g.,8p,g,2d6,2c6.,p,8g,8a,8c6,8a,e6,8p,e6,8p,d6.,p,8p,8g,8a,8c6,8a,2g6,b,c6.,8b,a,8g,8a,8c6,8a,2c6,d6,b,a,g.,8p,g,2d6,2c6";
const char * cinco = "Macarena:d=16,o=5,b=180:4f6,8f6,8f6,4f6,8f6,8f6,8f6,8f6,8f6,8f6,8f6,8a6,8c6,8c6,4f6,8f6,8f6,4f6,8f6,8f6,8f6,8f6,8f6,8f6,8d6,8c6,4p,4f6,8f6,8f6,4f6,8f6,8f6,8f6,8f6,8f6,8f6,8f6,8a6,4p,2c.7,4a6,8c7,8a6,8f6,4p,2p";
const char * xmas = "WeWishYo:d=4,o=5,b=200:d,g,8g,8a,8g,8f#,e,e,e,a,8a,8b,8a,8g,f#,d,d,b,8b,8c6,8b,8a,g,e,d,e,a,f#,2g,d,g,8g,8a,8g,8f#,e,e,e,a,8a,8b,8a,8g,f#,d,d,b,8b,8c6,8b,8a,g,e,d,e,a,f#,1g,d,g,g,g,2f#,f#,g,f#,e,2d,a,b,8a,8a,8g,8g,d6,d,d,e,a,f#,2g";
const char * macgyver = "MacGyver:d=8,o=5,b=160:c6,c6,c6,c6,c6,c6,c6,c6,2b,f#,4a,2g,p,c6,4c6,4b,a,b,a,4g,4e6,2a,c6,4c6,2b,p,f#,4a,2g,p,c6,4c6,4b,a,b,a,4g,4e6,2a,2b,c6,b,a,4c6,b,a,4d6,c6,b,4d6,c6,b,4e6,d6,e6,4f#6,4b,1g6";
const char * aniver = "TakeOnMe:d=16,o=5,b=100:8p,a#,a#,a#,8f#,8d#,8g#,8g#,g#,c6,c6,c#6,d#6,c#6,c#6,c#6,8g#,8f#,8a#,8a#,a#,g#,g#,a#,g#,a#,a#,a#,8f#,8d#,8g#,8g#,g#,c6,c6,c#6,d#6,c#6,c#6,c#6,8g#,8f#,8a#,8a#";
const char * melody = "NokiaTun:d=4,o=5,b=225:8e6,8d6,f#,g#,8c#6,8b,d,e,8b,8a,c#,e,2a";
const char * halloween = "Hallowee:d=4,o=5,b=160:8c6,8f,8f,8c6,8f,8f,8c6,8f,8c#6,8f,8c6,8f,8f,8c6,8f,8c6,8f,8c#6,8f,8b,8e,8e,8b,8e,8e,8b,8e,8c6,8e,8b,8e,8e,8b,8e,8e,8b,16e";
const char * mandy = "Mandy:d=8,o=6,b=120:d#,f,d#,d,4c.,f5,d#,d,c,4d#,f,d,4c,2a#5,f5,d,4c,a#5,d.5,4c,a#5,d,4c,16g5,2f5,f5,f5,d#,d,d#,4d,c,d,4c,2a#5,f5,d,4c,a#5,d,4c,a#5,a#5,4c,2c.5,f5,f5,d#,d,d#,d.,16c,4d,c,a#5,2a#.5";
const char * burgertime = "Burgertime:d=4,o=6,b=285:8f,8f,8f#,8f#,8g#,8g#,8a,8a,a#,f,a#,f,8g#,8c#7,8c7,8a#,8g#,8g,8g#,8g,g#,c#7,g#,c#7,g#,f7,g#,f7,g#,d#7,g#,c#7,g#,d#7,g#,c#7";
const char * tron = "tron:d=4,o=5,b=200:8f6,8c6,8g,e,8p,8f6,8c6,8g,8f6,8c6,8g,e.";
const char * mario = "mario:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6";
const char * smb_under = "smb_under:d=4,o=6,b=100:32c,32p,32c7,32p,32a5,32p,32a,32p,32a#5,32p,32a#,2p";
const char * finalcount = "FinalCou:d=4,o=5,b=125:16c#6,16b,c#6,f#,p.,16d6,16c#6,8d6,8c#6,b,p.,16d6,16c#6,d6,f#,p.,16b,16a,8b,8a,8g#,8b,a.,16c#6,16b,c#6,f#,p.,16d6,16c#6,8d6,8c#6,b,p.,16d6,16c#6,d6,f#,p.,16b,16a,8b,8a,8g#,8b,a.,16g#,16a,b.,16a,16b,8c#6,8b,8a,8g#,f#,d6,2c#.6,16c#6,16d6,16c#6,16b,1c#6,2p";
const char * adams = "AddamsFa:d=4,o=6,b=50:32p,32c#,16f#,32a#,16f#,32c#,16c,8g#,32f#,16f,32g#,16f,32c#,16a#5,8f#,32c#,16f#,32a#,16f#,32c#,16c,8g#,32f#,16f,32c#,16d#,32f,f#,32c#,32d#,32f,f#,32c#,32d#,32g,g#,32d#,32f,32g,16g#.,32d#,32f,32g,16g#.,32c#,32d#,32f,32f#";
const char * mspacman = "mspacman:d=4,o=5,b=100:32d,32e,8f,8a,8g,8a#,16a,16a#,16c6,16a,8g,8a#,16a,16a#,16c6,16a,16a#,16c6,16d6,16e6,8f6,8e6,8f6";
const char * galaga = "Galaga:d=4,o=5,b=125:8g4,32c,32p,8d,32f,32p,8e,32c,32p,8d,32a,32p,8g,32c,32p,8d,32f,32p,8e,32c,32p,8g,32b,32p,8c6,32a#,32p,8g#,32g,32p,8f,32d#,32p,8d,32a#4,32p,8a#,32c6,32p,8a#,32g,32p,16a,16f,16d,16g,16e,16d";
const char * xmen = "xmen:d=4,o=6,b=140:16f#5,16g5,16b5,16d,c#,8b5,8f#5,p,16f#5,16g5,16b5,16d,c#,8b5,8g5,p,16f#5,16g5,16b5,16d,c#,8b5,8d,2p,8c#,8b5,2p,16b5,16e,16f#,16g,f#,8e,8b5,p,16b5,16e,16f#,16g,f#,8e,8c,p,16f#5,16g5,16b5,16d,c#,8b5,8d,2p,8c#,8b5,2p";
const char * beethoven = "Beethoven - Fur Elise : d=4,o=5,b=140:8e6,8d#6,8e6,8d#6,8e6,8b,8d6,8c6,a,8p,8c,8e,8a,b,8p,8e,8g#,8b,c6,p,8e,8e6,8d#6,8e6,8d#6,8e6,8b,8d6,8c6,a,8p,8c,8e,8a,b,8p,8e,8c6,8b,2a";
const char * puffs = "Powerpuf:d=4,o=5,b=200:8c,p,8c,8p,8d#,8g,8a#,a.,8g,2p,8c6,p,8c6,8p,8d#6,8g6,8a#6,a#.6,8c7,p,8p,8c6,8c,p,8c,8p,8d#,8g,8a#,2c.6,p,1c,d#.,c.,g,1f#,p,8g,8c6";
// real6 fake5 real4 fake3 real2 fake1 real0
// RRRRRRR RRRRRRR RRRRRRR RRRRRRR RRRRRRR RRRRRRR RRRRRRR
//R R F F R R F F R R F F R R
//R S R F S F R S R F S F R S R F S F R S R
//R R F F R R F F R R F F R R
//R R F F R R F F R R F F R R
//R R F F R R F F R R F F R R
//R R F F R R F F R R F F R R
//R R F F R R F F R R F F R R
// RRRRRRR RRRRRRR RRRRRRR RRRRRRR RRRRRRR RRRRRRR RRRRRRR
//R R F F R R F F R R F F R R
//R S R F S F R S R F S F R S R F S F R S R
//R R F F R R F F R R F F R R
//R R F F R R F F R R F F R R
//R R F F R R F F R R F F R R
//R R F F R R F F R R F F R R
//R R F F R R F F R R F F R R
// RRRRRRR RRRRRRR RRRRRRR RRRRRRR RRRRRRR RRRRRRR RRRRRRR
//digit wiring order
// 4444444
// 3 5
// 3 5
// 3 5
// 3 5
// 3 5
// 3 5
// 3 5
// 6666666
// 2 0
// 2 0
// 2 0
// 2 0
// 2 0
// 2 0
// 2 0
// 1111111
// byte numbers digit order 0b6543210
byte numbers[] = {
0b0111111, // [0] 0
0b0100001, // [1] 1
0b1110110, // [2] 2
0b1110011, // [3] 3
0b1101001, // [4] 4
0b1011011, // [5] 5
0b1011111, // [6] 6
0b0110001, // [7] 7
0b1111111, // [8] 8
0b1111011, // [9] 9
0b0000000, // [10] all off, space
0b0100001, // [11] !
0b0101000, // [12] "
0b1101111, // [13] #
0b1011011, // [14] $
0b1100100, // [15] %
0b1100001, // [16] &
0b0001000, // [17] '
0b0011010, // [18] (
0b0110010, // [19] )
0b0011000, // [20] *
0b1001100, // [21] +
0b0000100, // [22] ,
0b1000000, // [23] -
0b0000010, // [24] .
0b1100100, // [25] /
0b1111000, // [26] degrees symbol
0b0010010, // [27] :
0b0010011, // [28] ;
0b1011000, // [29] <
0b1000010, // [30] =
0b1110000, // [31] >
0b1110100, // [32] ?
0b1110111, // [33] @
0b1111101, // [34] A
0b1001111, // [35] B
0b0011110, // [36] C(elsius)
0b1100111, // [37] D
0b1011110, // [38] E
0b1011100, // [39] F(ahrenheit)
0b0011111, // [40] G
0b1101101, // [41] H(umidity)
0b0001100, // [42] I
0b0100111, // [43] J
0b1011101, // [44] K
0b0001110, // [45] L
0b0010101, // [46] M
0b0111101, // [47] N
0b0111111, // [48] O
0b1111100, // [49] P
0b1111010, // [50] Q
0b0111100, // [51] R
0b1011011, // [52] S
0b1001110, // [53] T
0b0101111, // [54] U
0b0101111, // [55] V
0b0101010, // [56] W
0b1101101, // [57] X
0b1101011, // [58] Y
0b1110110, // [59] Z
0b0011110, // [60] left bracket
0b1001001, // [61] backslash
0b0110011, // [62] right bracket
0b0111000, // [63] carrot
0b0000010, // [64] underscore
0b0100000, // [65] aposhtophe
0b1110111, // [66] a
0b1001111, // [67] b
0b1000110, // [68] c
0b1100111, // [69] d
0b1111110, // [70] e
0b1011100, // [71] f
0b1111011, // [72] g
0b1001101, // [73] h
0b0000100, // [74] i
0b0000011, // [75] j
0b1011101, // [76] k
0b0001100, // [77] l
0b0000101, // [78] m
0b1000101, // [79] n
0b1000111, // [80] o
0b1111100, // [81] p
0b1111001, // [82] q
0b1000100, // [83] r
0b1011011, // [84] s
0b1001110, // [85] t
0b0000111, // [86] u
0b0000111, // [87] v
0b0000101, // [88] w
0b1101101, // [89] x
0b1101011, // [90] y
0b1110110, // [91] z
0b1100001, // [92] left squigly bracket
0b0001100, // [93] pipe
0b1001100, // [94] right squigly bracket
0b0010000, // [95] tilde
0b1010010 // [96] 3-lines (special pad)
};
void setup() {
Serial.begin(115200);
loadWebPageHandlers(); //load about 900 webpage handlers from the bottom of this sketch
// Initialize SPIFFS
Serial.println(F("Inizializing FS..."));
if (SPIFFS.begin()){
Serial.println(F("SPIFFS mounted correctly."));
}else{
Serial.println(F("!An error occurred during SPIFFS mounting"));
}
//load preferences from flash
loadSetupSettings(); //load all previously saved setting changes from the web interface
//init DS3231 RTC
if (! rtc.begin()) {
Serial.println("Couldn't find DS3231 RTC");
Serial.flush();
// abort();
}
//init audio gate inpute detection
pinMode(AUDIO_GATE_PIN, INPUT_PULLUP);
pinMode(MIC_IN_PIN, INPUT); //setup microphone
// init temp & humidity sensor
Serial.println(F("DHTxx test!"));
dht.begin();
//setup LEDs
FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(LEDs,NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(255);
fill_solid(LEDs, NUM_LEDS, CRGB::Black);
FastLED.show();
fakeClock(2); // blink 12:00 like old clocks once did
Config.autoReconnect = true; // Enable auto-reconnect.
Config.portalTimeout = 20000; // Sets timeout value for the captive portal
Config.retainPortal = true; // Retains the portal function after timed-out
Config.autoRise = true; // False for disabling the captive portal
Portal.config(Config);
Serial.println();
WiFi.hostname("shelfclock"); //set hostname
// setup AutoConnect to control WiFi
if (Portal.begin()) {
Serial.println("WiFi connected: " + WiFi.localIP().toString());
}
//use mdns for host name resolution
if (!MDNS.begin(host)) { //http://shelfclock
Serial.println("Error setting up MDNS responder!");
while (1) {
delay(1000);
}
}
Serial.println("mDNS responder started");
//init and set the time of the internal RTC from NTP server
configTime(gmtOffset_sec, (daylightOffset_sec * DSTime), ntpServer);
//was the internal RTC time set by the NTP server?, if not set it via the RTC DS3231 stored time, will be wrong if daylight savings time is active
if(!getLocalTime(&timeinfo)){
struct tm tm;
DateTime now = rtc.now();
tm.tm_year = now.year() - 1900;
tm.tm_mon = now.month() - 1;
tm.tm_mday = now.day();
tm.tm_hour = now.hour();
tm.tm_min = now.minute();
tm.tm_sec = now.second();
time_t t = mktime(&tm);
printf("NTP server not found, setting localtime from DS3231: %s", asctime(&tm));
struct timeval now1 = { .tv_sec = t };
settimeofday(&now1, NULL);
}
//did the DS3231 lose power (battery dead/changed), if so, set from time recieved from the NTP above
if (rtc.lostPower()) {
Serial.println("DS3231's RTC lost power, setting the time via NTP!");
if(!getLocalTime(&timeinfo)){Serial.println("Error, no NTP Server found!");}
int tempyear = (timeinfo.tm_year +1900);
int tempmonth = (timeinfo.tm_mon + 1);
rtc.adjust(DateTime(tempyear, tempmonth, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec));
}
printLocalTime();
//create something to know if now is not then
previousTimeMin = timeinfo.tm_min;
previousTimeHour = timeinfo.tm_hour;
previousTimeDay = timeinfo.tm_mday;
previousTimeWeek = ((timeinfo.tm_yday + 7 - (timeinfo.tm_wday ? (timeinfo.tm_wday - 1) : 6)) / 7);
previousTimeMonth = timeinfo.tm_mon;
// I assume this starts the OTA stuff
httpUpdateServer.setup(&server);
initGreenMatrix(); //setup lightshow functions
raininit(); //setup lightshow functions
allBlank(); //clear everything off the leds
//Webpage Handlers for SPIFFS access to flash
server.serveStatic("/", SPIFFS, "/index.html"); //send default webpage from root request
server.serveStatic("/", SPIFFS, "/", "max-age=86400");
//OTA firmware Upgrade Webpage Handlers
Serial.println("OTA Available");
server.on("/update", HTTP_POST, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
ESP.restart();
}, []() {
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
/* flashing firmware to ESP*/
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Update.printError(Serial);
}
}
});
//init rtttl (functions that play the alarms)
pinMode(BUZZER_PIN, OUTPUT);
rtttl::begin(BUZZER_PIN, smb_under); //play mario sound and set initial brightness level
while( !rtttl::done() ){GetBrightnessLevel(); rtttl::play();}
} //end of Setup()
void loop(){
server.handleClient();
Portal.handleRequest();
if (WiFi.status() == WL_IDLE_STATUS) {
ESP.restart();
delay(1000);
}
//Change Frequency so as to not use hard-coded delays
unsigned long currentMillis = millis();
//run everything inside here every second
if ((unsigned long)(currentMillis - prevTime) >= 1000) {
prevTime = currentMillis;
//struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
}
//setup time-passage trackers
int secs = timeinfo.tm_sec;
int currentTimeMin = timeinfo.tm_min;
byte m1 = currentTimeMin / 10;
byte m2 = currentTimeMin % 10;
int currentTimeHour = timeinfo.tm_hour;
int currentTimeDay = timeinfo.tm_mday;
int currentTimeWeek = ((timeinfo.tm_yday + 7 - (timeinfo.tm_wday ? (timeinfo.tm_wday - 1) : 6)) / 7);
int currentTimeMonth = timeinfo.tm_mon;
checkSleepTimer(); //time to sleep?
if ((currentTimeHour == 23 && currentTimeMin == 11 && timeinfo.tm_sec == 0 && clockDisplayType != 1) || (currentTimeHour == 11 && currentTimeMin == 11 && timeinfo.tm_sec == 0)) { scroll("MAkE A WISH"); } //at 1111 make a wish
if (abs(currentTimeMin - previousTimeMin) >= 1) { //run every minute
previousTimeMin = currentTimeMin;
randomMinPassed = 1;
GetBrightnessLevel();
if (scrollFrequency == 1 && (suspendType == 0 || isAsleep == 0) && scrollOverride == 1 && ((clockMode != 11) && (clockMode != 1) && (clockMode != 4))) {displayScrollMode();}
if (scrollFrequency == 1 && randomSpectrumMode == 1 && clockMode == 9) {allBlank(); spectrumMode = random(11);}
} //end of run every minute
if ((m2 == 0 || m2 == 5) && (secs == 0)) { //run every 5 minutes
if (scrollFrequency == 2 && (suspendType == 0 || isAsleep == 0) && scrollOverride == 1 && ((clockMode != 11) && (clockMode != 1) && (clockMode != 4))) {displayScrollMode();}
if (scrollFrequency == 2 && randomSpectrumMode == 1 && clockMode == 9) {allBlank(); spectrumMode = random(11);}
} //end of run every 5 minutes
if ((m2 == 0) && (secs == 0)) { //run every 10 minutes
if (scrollFrequency == 3 && (suspendType == 0 || isAsleep == 0) && scrollOverride == 1 && ((clockMode != 11) && (clockMode != 1) && (clockMode != 4))) {displayScrollMode();}
if (scrollFrequency == 3 && randomSpectrumMode == 1 && clockMode == 9) {allBlank(); spectrumMode = random(11);}
} //end of run every 10 minutes
if (((m1 == 0 && m2 == 0) || (m1 == 1 && m2 == 5) || (m1 == 3 && m2 == 0) || (m1 == 4 && m2 == 5)) && (secs == 0)) { //run every 15 minutes
if (scrollFrequency == 4 && (suspendType == 0 || isAsleep == 0) && scrollOverride == 1 && ((clockMode != 11) && (clockMode != 1) && (clockMode != 4))) {displayScrollMode();}
if (scrollFrequency == 4 && randomSpectrumMode == 1 && clockMode == 9) {allBlank(); spectrumMode = random(11);}
} //end of run every 15 minutes
if (((m1 == 0 && m2 == 0) || (m1 == 3 && m2 == 0)) && (secs == 0)) { //run every 30 minutes
if (scrollFrequency == 5 && (suspendType == 0 || isAsleep == 0) && scrollOverride == 1 && ((clockMode != 11) && (clockMode != 1) && (clockMode != 4))) {displayScrollMode();}
if (scrollFrequency == 5 && randomSpectrumMode == 1 && clockMode == 9) {allBlank(); spectrumMode = random(11);}
} //end of run every 30 minutes
if (abs(currentTimeHour - previousTimeHour) >= 1) { //run every hour
previousTimeHour = currentTimeHour;
randomHourPassed = 1;
if (scrollFrequency == 6 && (suspendType == 0 || isAsleep == 0) && scrollOverride == 1 && ((clockMode != 11) && (clockMode != 1) && (clockMode != 4))) {displayScrollMode();}
if (scrollFrequency == 6 && randomSpectrumMode == 1 && clockMode == 9) {allBlank(); spectrumMode = random(11);}
} //end of run every hour
if (abs(currentTimeDay - previousTimeDay) >= 1) {
previousTimeDay = currentTimeDay;
randomDayPassed = 1;
configTime(gmtOffset_sec, (daylightOffset_sec * DSTime), ntpServer);
int tempyear = (timeinfo.tm_year +1900);
int tempmonth = (timeinfo.tm_mon + 1);
rtc.adjust(DateTime(tempyear, tempmonth, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec));
daysUptime = daysUptime + 1;
}
if (abs(currentTimeWeek - previousTimeWeek) >= 1) { previousTimeWeek = currentTimeWeek; randomWeekPassed = 1;}
if (abs(currentTimeMonth - previousTimeMonth) >= 1) { previousTimeMonth = currentTimeMonth; randomMonthPassed = 1;}
if (realtimeMode == 0) { //give autodim sensors some CPU time, update display
GetBrightnessLevel();
FastLED.show();
}
//give the various clock modes CPU time every 1 seconds
if ((suspendType == 0 || isAsleep == 0) && clockMode == 0) {
displayTimeMode();
} else if (clockMode == 1) {
displayCountdownMode();
} else if ((suspendType == 0 || isAsleep == 0) && clockMode == 2) {
displayTemperatureMode();
} else if ((suspendType == 0 || isAsleep == 0) && clockMode == 3) {
displayScoreboardMode();
} else if (clockMode == 4) {
displayStopwatchMode();
} else if ((suspendType == 0 || isAsleep == 0) && clockMode == 5) {
displayLightshowMode();
} else if ((suspendType == 0 || isAsleep == 0) && clockMode == 6) {
//notused
} else if ((suspendType == 0 || isAsleep == 0) && clockMode == 7) {
displayDateMode();
} else if ((suspendType == 0 || isAsleep == 0) && clockMode == 8) {
displayHumidityMode();
} else if (clockMode == 9) {
//spectrum mode
} else if (clockMode == 10) {
//display off
} else if ((suspendType == 0 || isAsleep == 0) && clockMode == 11) {
displayScrollMode();
}
ShelfDownLights();
randomMinPassed = 0;
randomHourPassed = 0;
randomDayPassed = 0;
randomWeekPassed = 0;
randomMonthPassed = 0;
if (brightness != 10) { //if not set to auto-dim just use user set brightness
FastLED.setBrightness(brightness);
} else if (brightness == 10) { //auto-dim use the value from above
FastLED.setBrightness(lightSensorValue);
}
}
displayRealtimeMode(); //always run outside time loop for speed, but only really show when it's needed
} // end of main loop
void displayTimeMode() { //main clock function
currentMode = 0;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
}
// printLocalTime(); //display time in monitor window
int hour = timeinfo.tm_hour;
int mins = timeinfo.tm_min;
int secs = timeinfo.tm_sec;
if (clockDisplayType != 1 && hour > 12){hour = hour - 12; }
if (clockDisplayType != 1 && hour < 1){hour = hour + 12; }
byte h1 = hour / 10;
byte h2 = hour % 10;
byte m1 = mins / 10;
byte m2 = mins % 10;
byte s1 = secs / 10;
byte s2 = secs % 10;
if (ClockColorSettings == 0) { hourColor = CRGB(r1_val, g1_val, b1_val); minColor = CRGB(r2_val, g2_val, b2_val); }
if (ClockColorSettings == 1) { hourColor = CRGB(r1_val, g1_val, b1_val); minColor = hourColor; }
if ((ClockColorSettings == 2 && pastelColors == 0) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { hourColor = CHSV(random(0, 255), 255, 255); minColor = CHSV(random(0, 255), 255, 255);}
if ((ClockColorSettings == 2 && pastelColors == 1) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { hourColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); minColor = CRGB(random(0, 255), random(0, 255), random(0, 255));}
if ((ClockColorSettings == 3 && pastelColors == 0) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { hourColor = CHSV(random(0, 255), 255, 255); minColor = hourColor;}
if ((ClockColorSettings == 3 && pastelColors == 1) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { hourColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); minColor = hourColor;}
if ((clockDisplayType == 3)) { //Blinking Center Light
if (h1 > 0) {
tinyhourColor = hourColor;
if (ClockColorSettings == 4 && pastelColors == 0){ tinyhourColor = CHSV(random(0, 255), 255, 255); }
if (ClockColorSettings == 4 && pastelColors == 1){ tinyhourColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); }
for (int i=(32*LEDS_PER_SEGMENT); i<(33*LEDS_PER_SEGMENT); i++) { LEDs[i] = tinyhourColor;}
if (ClockColorSettings == 4 && pastelColors == 0){ tinyhourColor = CHSV(random(0, 255), 255, 255); }
if (ClockColorSettings == 4 && pastelColors == 1){ tinyhourColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); }
for (int i=(33*LEDS_PER_SEGMENT); i<(34*LEDS_PER_SEGMENT); i++) { LEDs[i] = tinyhourColor;}
} else {
for (int i=(32*LEDS_PER_SEGMENT); i<(34*LEDS_PER_SEGMENT); i++) { LEDs[i] = CRGB::Black;}
}
displayNumber(h2,5,hourColor);
displayNumber(m1,2,minColor);
displayNumber(m2,0,minColor);
BlinkDots();
}
if (clockDisplayType == 2) { //12-hour Space-Padded
if (h1 < 1) { displayNumber(10,6,hourColor); }
else { displayNumber(h1,6,hourColor); }
displayNumber(h2,4,hourColor);
displayNumber(m1,2,minColor);
displayNumber(m2,0,minColor);
}
if (clockDisplayType == 0) { //center set and hour is less than 1 and no 0 is set, default
if (h1 > 0) {
tinyhourColor = hourColor;
if (ClockColorSettings == 4 && pastelColors == 0){ tinyhourColor = CHSV(random(0, 255), 255, 255); }
if (ClockColorSettings == 4 && pastelColors == 1){ tinyhourColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); }
for (int i=(32*LEDS_PER_SEGMENT); i<(33*LEDS_PER_SEGMENT); i++) { LEDs[i] = tinyhourColor;}
if (ClockColorSettings == 4 && pastelColors == 0){ tinyhourColor = CHSV(random(0, 255), 255, 255); }
if (ClockColorSettings == 4 && pastelColors == 1){ tinyhourColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); }
for (int i=(33*LEDS_PER_SEGMENT); i<(34*LEDS_PER_SEGMENT); i++) { LEDs[i] = tinyhourColor;}
} else {for (int i=(32*LEDS_PER_SEGMENT); i<(34*LEDS_PER_SEGMENT); i++) { LEDs[i] = CRGB::Black;}
}
displayNumber(h2,5,hourColor);
displayNumber(m1,3,minColor);
displayNumber(m2,1,minColor);
}
if (clockDisplayType == 1) { //24-hour Military Time
if (h1 < 1) { displayNumber(0,6,hourColor);}
else { displayNumber(h1,6,hourColor);}
displayNumber(h2,4,hourColor);
displayNumber(m1,2,minColor);
displayNumber(m2,0,minColor);
}
if (clockDisplayType == 4) { //New Year Countdown
int hour = timeinfo.tm_hour;
int mins = timeinfo.tm_min;
int secs = timeinfo.tm_sec;
int mday = timeinfo.tm_mday;
int mont = timeinfo.tm_mon + 1;
int year = (timeinfo.tm_year +1900);
int daysInMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int daysLeft = 0;
if (((year % 4 == 0) && (year % 100 != 0)) || ((year % 100 != 0) && (year % 400 == 0))){daysLeft = daysLeft + 1;} //leapyear?
if (mont !=12) {for (int i=(mont+1); i<13; i++) { daysLeft = daysLeft + daysInMonth[i-1];}}
daysLeft = daysLeft + (daysInMonth[mont-1]-mday);
int hoursLeft = (daysLeft * 24) + (23 - hour);
bool DST; //start of DST adjustment algorithm
int y = year-2000; // uses two digit year
int x = (y + y/4 + 2) % 7; // remainder will identify which day of month
if(mont == 3 && mday == (14 - x) && hour >= 2){DST = 1;} //DST begins on 2nd Sunday of March @ 2:00 AM
if((mont == 3 && mday > (14 - x)) || mont > 3){DST = 1;}
if(mont == 11 && mday == (7 - x) && hour >= 2){DST = 0; } //DST ends on 1st Sunday of Nov @ 2:00 AM
if((mont == 11 && mday > (7 - x)) || mont > 11 || mont < 3){DST = 0;}
if(DST == 1) {hoursLeft = hoursLeft + 1; } //adjust for DST
int minutesLeft = (hoursLeft * 60) + (59 - mins);
int secondsLeft = (minutesLeft * 60) + (60 - secs);
int inputNums = hoursLeft;
if ((minutesLeft <= 9999) && (secondsLeft > 9999)) {inputNums = minutesLeft; hourColor = minColor;}
if ((secondsLeft <= 9999) && (secondsLeft > 10)) {inputNums = secondsLeft; hourColor = colonColor;}
if (secondsLeft <= 10) {inputNums = secondsLeft;FastLED.setBrightness(255);hourColor = CRGB::Red;}
byte ledNum1 = inputNums / 1000;
byte ledNum2 = (inputNums - (ledNum1 * 1000)) / 100;
byte ledNum3 = ((inputNums - (ledNum1 * 1000)) - (ledNum2 * 100)) / 10;
byte ledNum4 = inputNums % 10;
if (inputNums >= 1000) {
if (clearOldLeds != 1000){clearOldLeds = 1000; allBlank();}
displayNumber(ledNum1,6,hourColor);
displayNumber(ledNum2,4,hourColor);
displayNumber(ledNum3,2,hourColor);
displayNumber(ledNum4,0,hourColor);
}
if ((inputNums >= 100) && (inputNums < 1000)) {
if (clearOldLeds != 100){clearOldLeds = 100; allBlank();}
displayNumber(ledNum2,5,hourColor);
displayNumber(ledNum3,3,hourColor);
displayNumber(ledNum4,1,hourColor);
}
if ((inputNums > 0) && (inputNums < 100)) {
if (clearOldLeds != 10){clearOldLeds = 10; allBlank();}
displayNumber(ledNum3,4,hourColor);
displayNumber(ledNum4,2,hourColor);
}
if (mday == 1 && mont == 1 && hour == 0 && mins == 0 && secs <= 3) { happyNewYear();}
// if (mday == 7 && mont == 6 && hour == 16 && mins == 10 && secs <= 3) { happyNewYear();} //for testing
}
} // end of update clock
void displayDateMode() { //main date function
currentMode = 0;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
}
int mday = timeinfo.tm_mday;
int mont = timeinfo.tm_mon + 1;
int year = (timeinfo.tm_year +1900)-2000;
byte d1 = mday / 10;
byte d2 = mday % 10;
byte m1 = mont / 10;
byte m2 = mont % 10;
byte y1 = year / 10;
byte y2 = year % 10;
if (DateColorSettings == 0) { monthColor = CRGB(r5_val, g5_val, b5_val); dayColor = CRGB(r4_val, g4_val, b4_val); separatorColor = CRGB(r6_val, g6_val, b6_val);}
if (DateColorSettings == 1) { monthColor = CRGB(r5_val, g5_val, b5_val); dayColor = monthColor; separatorColor = CRGB(r6_val, g6_val, b6_val);}
if ((DateColorSettings == 2 && pastelColors == 0) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { monthColor = CHSV(random(0, 255), 255, 255); dayColor = CHSV(random(0, 255), 255, 255);separatorColor = CHSV(random(0, 255), 255, 255);}
if ((DateColorSettings == 2 && pastelColors == 1) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { monthColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); dayColor = CRGB(random(0, 255), random(0, 255), random(0, 255));separatorColor = CRGB(random(0, 255), random(0, 255), random(0, 255));}
if ((DateColorSettings == 3 && pastelColors == 0) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { monthColor = CHSV(random(0, 255), 255, 255); dayColor = monthColor; separatorColor = monthColor;}
if ((DateColorSettings == 3 && pastelColors == 1) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { monthColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); dayColor = monthColor; separatorColor = monthColor;}
if ((dateDisplayType == 5)) { //With "." Separator (MM.DD)
if (m1 > 0) {
tinymonthColor = monthColor;
if (DateColorSettings == 4 && pastelColors == 0){ tinymonthColor = CHSV(random(0, 255), 255, 255); }
if (DateColorSettings == 4 && pastelColors == 1){ tinymonthColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); }
for (int i=(32*LEDS_PER_SEGMENT); i<(33*LEDS_PER_SEGMENT); i++) { LEDs[i] = tinymonthColor;}
if (DateColorSettings == 4 && pastelColors == 0){ tinymonthColor = CHSV(random(0, 255), 255, 255); }
if (DateColorSettings == 4 && pastelColors == 1){ tinymonthColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); }
for (int i=(33*LEDS_PER_SEGMENT); i<(34*LEDS_PER_SEGMENT); i++) { LEDs[i] = tinymonthColor;}
} else {for (int i=(32*LEDS_PER_SEGMENT); i<(34*LEDS_PER_SEGMENT); i++) { LEDs[i] = CRGB::Black;}
}
displayNumber(m2,5,monthColor);
displayNumber(d1,2,dayColor);
displayNumber(d2,0,dayColor);
if ((DateColorSettings == 4 ) && pastelColors == 0){ separatorColor = CHSV(random(0, 255), 255, 255); }
if ((DateColorSettings == 4 ) && pastelColors == 1){ separatorColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); }
for (int i=(20*LEDS_PER_SEGMENT); i<(21*LEDS_PER_SEGMENT); i++) { LEDs[i] = separatorColor;} //separator
}
if (dateDisplayType == 1) { //Space-Padded (MMDD)
if (m1 < 1) { displayNumber(10,6,monthColor); }
else { displayNumber(m1,6,monthColor); }
displayNumber(m2,4,monthColor);
displayNumber(d1,2,dayColor);
displayNumber(d2,0,dayColor);
}
if (dateDisplayType == 2) { //Center Dates (1MDD)
if (m1 > 0) {
tinymonthColor = monthColor;
if (DateColorSettings == 4 && pastelColors == 0){ tinymonthColor = CHSV(random(0, 255), 255, 255); }
if (DateColorSettings == 4 && pastelColors == 1){ tinymonthColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); }
for (int i=(32*LEDS_PER_SEGMENT); i<(33*LEDS_PER_SEGMENT); i++) { LEDs[i] = tinymonthColor;}
if (DateColorSettings == 4 && pastelColors == 0){ tinymonthColor = CHSV(random(0, 255), 255, 255); }
if (DateColorSettings == 4 && pastelColors == 1){ tinymonthColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); }
for (int i=(33*LEDS_PER_SEGMENT); i<(34*LEDS_PER_SEGMENT); i++) { LEDs[i] = tinymonthColor;}
} else {for (int i=(32*LEDS_PER_SEGMENT); i<(34*LEDS_PER_SEGMENT); i++) { LEDs[i] = CRGB::Black;}
}
displayNumber(m2,5,monthColor);
displayNumber(d1,3,dayColor);
displayNumber(d2,1,dayColor);
}
if (dateDisplayType == 0) { //Zero-Padded (MMDD)
if (m1 < 1) { displayNumber(0,6,monthColor);}
else { displayNumber(m1,6,monthColor);}
displayNumber(m2,4,monthColor);
displayNumber(d1,2,dayColor);
displayNumber(d2,0,dayColor);
}
if (dateDisplayType == 4) { //Just Numeric Day (DD)
if (d1 < 1) {
displayNumber(d2,3,dayColor);
} else {
displayNumber(d1,4,dayColor);
displayNumber(d2,2,dayColor);
}
}
if (dateDisplayType == 3) { //Just Day of Week (Sun)
if (timeinfo.tm_wday == 1) {displayNumber(78,5,dayColor);displayNumber(80,3,dayColor); displayNumber(79,1,dayColor);} //mon
if (timeinfo.tm_wday == 2) {displayNumber(85,6,dayColor);displayNumber(54,4,dayColor); displayNumber(38,2,dayColor); displayNumber(52,0,dayColor);} //tUES
if (timeinfo.tm_wday == 3) {displayNumber(88,5,dayColor);displayNumber(38,3,dayColor); displayNumber(69,1,dayColor);} //wEd
if (timeinfo.tm_wday == 4) {displayNumber(85,6,dayColor);displayNumber(73,4,dayColor); displayNumber(86,2,dayColor); displayNumber(83,0,dayColor);} //thur
if (timeinfo.tm_wday == 5) {displayNumber(39,5,dayColor);displayNumber(83,3,dayColor); displayNumber(42,1,dayColor);} //FrI
if (timeinfo.tm_wday == 6) {displayNumber(52,5,dayColor);displayNumber(34,3,dayColor); displayNumber(85,1,dayColor);} //SAt
if (timeinfo.tm_wday == 0) {displayNumber(52,5,dayColor);displayNumber(86,3,dayColor); displayNumber(79,1,dayColor);} //Sun
}
if (dateDisplayType == 6) { //Just Year (YYYY)
displayNumber(2,6,monthColor);
displayNumber(0,4,monthColor);
displayNumber(y1,2,dayColor);
displayNumber(y2,0,dayColor);
}
} // end of update date
void displayTemperatureMode() { //miain temp function
currentMode = 0;
float h = dht.readHumidity(); // read humidity
float sensorTemp = dht.readTemperature(); // read temperature
float f = dht.readTemperature(true);
if (isnan(h) || isnan(sensorTemp) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float correctedTemp = sensorTemp + temperatureCorrection;
if (temperatureSymbol == 39) { correctedTemp = ((sensorTemp * 1.8000) + 32) + temperatureCorrection; }
byte t1 = 0;
byte t2 = 0;
int tempDecimal = correctedTemp * 10;
if (correctedTemp >= 100) {
int tempHundred = correctedTemp / 10;
t1 = tempHundred / 10;
t2 = tempHundred % 10;
} else {
t2 = int(correctedTemp) / 10;
}
byte t3 = int(correctedTemp) % 10;
byte t4 = tempDecimal % 10;
if (tempColorSettings == 0) {tempColor = CRGB(r7_val, g7_val, b7_val); typeColor = CRGB(r8_val, g8_val, b8_val); degreeColor = CRGB(r9_val, g9_val, b9_val);}
if (tempColorSettings == 1) {tempColor = CRGB(r7_val, g7_val, b7_val); typeColor = tempColor; degreeColor = CRGB(r9_val, g9_val, b9_val);}
if ((tempColorSettings == 2 && pastelColors == 0) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { tempColor = CHSV(random(0, 255), 255, 255); typeColor = CHSV(random(0, 255), 255, 255);degreeColor = CHSV(random(0, 255), 255, 255);}
if ((tempColorSettings == 2 && pastelColors == 1) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { tempColor = CRGB(random(0, 255), random(0, 255), random(0, 255)); typeColor = CRGB(random(0, 255), random(0, 255), random(0, 255));degreeColor = CRGB(random(0, 255), random(0, 255), random(0, 255));}
if ((tempColorSettings == 3 && pastelColors == 0) && ( (ColorChangeFrequency == 0 ) || (ColorChangeFrequency == 1 && randomMinPassed == 1) || (ColorChangeFrequency == 2 && randomHourPassed == 1) || (ColorChangeFrequency == 3 && randomDayPassed == 1) || (ColorChangeFrequency == 4 && randomWeekPassed == 1) || (ColorChangeFrequency == 5 && randomMonthPassed == 1) )) { tempColor = CHSV(random(0, 255), 255, 255); typeColor = tempColor; degreeColor = tempColor;}