-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPongESP32.ino
1943 lines (1675 loc) · 67.1 KB
/
PongESP32.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 <SPI.h>
#include "ESP32-RGB32x16MatrixPanel-I2S-DMA.h"
#include <NTPClient.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include "font3x5.h"
#include "font5x5.h"
#include "blinky.h"
#include <SPIFFS.h>
#include <simpleDSTadjust.h>
/*
**The MIT License (MIT)
Copyright (c) 2018 by Daniel Eichhorn - ThingPulse
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
See more at https://thingpulse.com
Credits on the RGB display routines:
Louis Beaudoin <https://github.com/pixelmatix/SmartMatrix/tree/teensylc>
and Sprite_TM: https://www.esp32.com/viewtopic.php?f=17&t=3188 and https://www.esp32.com/viewtopic.php?f=13&t=3256
and mrFaptastic: https://github.com/mrfaptastic/ESP32-RGB64x32MatrixPanel-I2S-DMA
Credits on Pong Clock
Paul Kourany: https://github.com/pkourany/RGBPongClock
/* RGB Pong Clock - Andrew Holmes @pongclock
** Inspired by, and shamelessly derived from
** Nick's LED Projects
** https://123led.wordpress.com/about/
**
** Videos of the clock in action:
** https://vine.co/v/hwML6OJrBPw
** https://vine.co/v/hgKWh1KzEU0
** https://vine.co/v/hgKz5V0jrFn
** I run this on a Mega 2560, your milage on other chips may vary,
** Can definately free up some memory if the bitmaps are shrunk down to size.
** Uses an Adafruit 16x32 RGB matrix availble from here:
** http://www.phenoptix.com/collections/leds/products/16x32-rgb-led-matrix-panel-by-adafruit
** This microphone:
** http://www.phenoptix.com/collections/adafruit/products/electret-microphone-amplifier-max4466-with-adjustable-gain-by-adafruit-1063
** a DS1307 RTC chip (not sure where I got that from - was a spare)
** and an Ethernet Shield
** http://hobbycomponents.com/index.php/dvbd/dvbd-ardu/ardu-shields/2012-ethernet-w5100-network-shield-for-arduino-uno-mega-2560-1280-328.html
**
** All code adjusted for ESP32 and RGB32x16 for the Eindhoven IoT Workshop by Frank Beks https://github.com/galagaking
*
*/
#include <ESPHTTPClient.h>
#include <JsonListener.h>
// time
#include <time.h> // time() ctime()
#include <sys/time.h> // struct timeval
//#include <coredecls.h> // settimeofday_cb()
#include <OpenWeatherMapCurrent.h>
#include <OpenWeatherMapForecast.h>
#include "WeatherStationFonts.h"
#include "WeatherStationImages.h"
/***************************
* Begin Settings
**************************/
// WIFI
//const char* WIFI_SSID = "<YOUR SSID>";
//const char* WIFI_PWD = "<YOUR WIFI CODE>";
#define TZ 2 // (utc+) TZ in hours
#define DST_MN 60 // use 60mn for summer time in some countries
// Setup
const int UPDATE_INTERVAL_SECS = 1 * 60; // Update every 1 minutes
// OpenWeatherMap Settings
// Sign up here to get an API key:
// https://docs.thingpulse.com/how-tos/openweathermap-key/
String OPEN_WEATHER_MAP_APP_ID = "<YOUR WEATHER API>";
/*
Go to https://openweathermap.org/find?q= and search for a location. Go through the
result set and select the entry closest to the actual location you want to display
data for. It'll be a URL like https://openweathermap.org/city/2657896. The number
at the end is what you assign to the constant below.
*/
String OPEN_WEATHER_MAP_LOCATION_ID = "2756253";
// Pick a language code from this list:
// Arabic - ar, Bulgarian - bg, Catalan - ca, Czech - cz, German - de, Greek - el,
// English - en, Persian (Farsi) - fa, Finnish - fi, French - fr, Galician - gl,
// Croatian - hr, Hungarian - hu, Italian - it, Japanese - ja, Korean - kr,
// Latvian - la, Lithuanian - lt, Macedonian - mk, Dutch - nl, Polish - pl,
// Portuguese - pt, Romanian - ro, Russian - ru, Swedish - se, Slovak - sk,
// Slovenian - sl, Spanish - es, Turkish - tr, Ukrainian - ua, Vietnamese - vi,
// Chinese Simplified - zh_cn, Chinese Traditional - zh_tw.
String OPEN_WEATHER_MAP_LANGUAGE = "nl";
const uint8_t MAX_FORECASTS = 4;
OpenWeatherMapCurrentData currentWeather;
OpenWeatherMapCurrent currentWeatherClient;
OpenWeatherMapForecastData forecasts[MAX_FORECASTS];
OpenWeatherMapForecast forecastClient;
const boolean IS_METRIC = true;
// Adjust according to your language
const String WDAY_NAMES[] = {"ZON", "MAA", "DIN", "WOE", "DON", "VRI", "ZAT"};
const String MONTH_NAMES[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OKT", "NOV", "DEC"};
struct dstRule StartRule = {"CEST", Last, Sun, Mar, 2, 3600}; // Central European Summer Time = UTC/GMT +2 hours
struct dstRule EndRule = {"CET", Last, Sun, Oct, 2, 0}; // Central European Time = UTC/GMT +1 hour
#define UTC_OFFSET +1
#define NTP_SERVERS "0.ch.pool.ntp.org", "1.ch.pool.ntp.org", "2.ch.pool.ntp.org"
simpleDSTadjust dstAdjusted(StartRule, EndRule);
// flag changed in the ticker function every 10 minutes
bool readyForWeatherUpdate = false;
String lastUpdate = "--";
#if defined(ESP8266)
Ticker display_ticker;
#else
long timeSinceLastWUpdate = 0;
#endif
//declaring prototypes
void updateData();
void drawDateTime();
void setReadyForWeatherUpdate();
uint8_t fdow(unsigned long);
#define DEBUGME
// allow us to use itoa() in this scope
extern char* itoa(int a, char* buffer, unsigned char radix);
#ifdef DEBUGME
#define DEBUGp(message) Serial.print(message)
#define DEBUGpln(message) Serial.println(message)
#else
#define DEBUGp(message)
#define DEBUGpln(message)
#endif
RGB32x16MatrixPanel_I2S_DMA display;
// Some standard colors
uint16_t myRED = display.color565(255, 0, 0);
uint16_t myGREEN = display.color565(0, 255, 0);
uint16_t myBLUE = display.color565(0, 0, 255);
uint16_t myWHITE = display.color565(255, 255, 255);
uint16_t myYELLOW = display.color565(255, 255, 0);
uint16_t myCYAN = display.color565(0, 255, 255);
uint16_t myMAGENTA = display.color565(255, 0, 255);
uint16_t myBLACK = display.color565(0, 0, 0);
uint16_t myCOLORS[8]={myRED,myGREEN,myBLUE,myWHITE,myYELLOW,myCYAN,myMAGENTA,myBLACK};
uint8_t static weather_icons[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0xff,0xe0,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xdf,0x07,0xdf,0x07,0xdf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x20,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xdf,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xdf,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00
,0x00,0x20,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0xff,0xe0,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xdf,0x07,0xff,0x07,0xdf,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xdf,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xdf,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x07,0xdf,0x07,0xdf,0x07,0xff,0xff,0xe0,0xff,0xe0,0x00,0x00
,0x00,0x00,0xff,0xe0,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xdf,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0xff,0xe0,0x00,0x20,0x00,0x00,0x07,0xdf,0x07,0xdf,0x07,0xdf,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xdf,0x07,0xdf,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0xff,0xff,0x07,0xff,0x07,0xff,0x07,0xdf,0x07,0xff,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xdf,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xdf,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x07,0xff,0x00,0x20,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xdf,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xdf,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xdf,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0xff,0xe0,0xff,0xe0,0x07,0xdf,0x07,0xdf,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00
,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0xff,0xe0,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0xff,0xe0,0xff,0xe0,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xdf,0x07,0xdf,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xdf,0x07,0xff,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xdf,0x07,0xdf,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xdf,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0x07,0xdf,0x07,0xff,0x07,0xff,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
uint8_t icon_index=0;
#define SHOWCLOCK 100
#define MAX_CLOCK_MODE 7 // Number of clock modes
/********** RGB565 Color definitions **********/
#define Black 0x0000
#define Navy 0x000F
#define DarkGreen 0x03E0
#define DarkCyan 0x03EF
#define Maroon 0x7800
#define Purple 0x780F
#define Olive 0x7BE0
#define LightGrey 0xC618
#define DarkGrey 0x7BEF
#define Blue 0x001F
#define Green 0x07E0
#define Cyan 0x07FF
#define Red 0xF800
#define Magenta 0xF81F
#define Yellow 0xFFE0
#define White 0xFFFF
#define Orange 0xFD20
#define GreenYellow 0xAFE5
#define Pink 0xF81F
/**********************************************/
#define X_MAX 31 // Matrix X max LED coordinate (for 2 displays placed next to each other)
#define Y_MAX 15
#define BAT1_X 2 // Pong left bat x pos (this is where the ball collision occurs, the bat is drawn 1 behind these coords)
#if (X_MAX == 63)
#define BAT2_X 60
#else
#define BAT2_X 28
#endif
/********** PACMAN definitions **********/
#define usePACMAN // Uncomment to enable PACMAN animations
int powerPillEaten = 0;
/********* USING SPECIAL MESSAGES **********/
#define USING_SPECIAL_MESSAGES
#ifdef USING_SPECIAL_MESSAGES
struct SpecialDays {
int month, day;
char* message;
};
const SpecialDays ourHolidays[] = { //keep message to < 40 chars
{ 0, 0, "HAVE A NICE DAY"},
{ 1, 1, "HAPPY NEW YEAR"},
{ 2, 14, "HAPPY ST PATRICKS DAY"},
{ 4, 1, "HAPPY BIRTHDAY TOM"},
{ 7, 4, "HAPPY 4TH OF JULY"},
{ 7, 15, "HAPPY ANNIVERSARY"},
{ 8, 12, "HAPPY BIRTHDAY GRAMPA"},
{ 9, 26, "HAPPY BIRTHDAY CHASE AND CHANDLER"},
{10, 31, "HAPPY HALLOWEEN"},
{11, 1, "HAPPY BIRTHDAY PATCHES"},
{12, 18, "Birthday of Pong!"},
{12, 25, "MERRY CHRISTMAS"}
};
#endif
int stringPos;
int badWeatherCall;
char w_temp[8][7] = {""};
char w_id[8][4] = {""};
char *dstAbbrev;
char time_str[11];
time_t now;
struct tm * timeinfo;
boolean wasWeatherShownLast= true;
unsigned long lastWeatherTime =0;
int mode_changed = 0; // Flag if mode changed.
bool mode_quick = false; // Quick weather display
int clock_mode = 2; // Default clock mode (1 = pong)
uint16_t showClock = SHOWCLOCK; // Default time to show a clock face
unsigned long modeSwitch;
unsigned long updateCTime; // 24hr timer for resyncing cloud time
/************ PLASMA definitions **********/
static const int8_t PROGMEM sinetab[256] = {
0, 2, 5, 8, 11, 15, 18, 21,
24, 27, 30, 33, 36, 39, 42, 45,
48, 51, 54, 56, 59, 62, 65, 67,
70, 72, 75, 77, 80, 82, 85, 87,
89, 91, 93, 96, 98, 100, 101, 103,
105, 107, 108, 110, 111, 113, 114, 116,
117, 118, 119, 120, 121, 122, 123, 123,
124, 125, 125, 126, 126, 126, 126, 126,
127, 126, 126, 126, 126, 126, 125, 125,
124, 123, 123, 122, 121, 120, 119, 118,
117, 116, 114, 113, 111, 110, 108, 107,
105, 103, 101, 100, 98, 96, 93, 91,
89, 87, 85, 82, 80, 77, 75, 72,
70, 67, 65, 62, 59, 56, 54, 51,
48, 45, 42, 39, 36, 33, 30, 27,
24, 21, 18, 15, 11, 8, 5, 2,
0, -3, -6, -9, -12, -16, -19, -22,
-25, -28, -31, -34, -37, -40, -43, -46,
-49, -52, -55, -57, -60, -63, -66, -68,
-71, -73, -76, -78, -81, -83, -86, -88,
-90, -92, -94, -97, -99,-101,-102,-104,
-106,-108,-109,-111,-112,-114,-115,-117,
-118,-119,-120,-121,-122,-123,-124,-124,
-125,-126,-126,-127,-127,-127,-127,-127,
-128,-127,-127,-127,-127,-127,-126,-126,
-125,-124,-124,-123,-122,-121,-120,-119,
-118,-117,-115,-114,-112,-111,-109,-108,
-106,-104,-102,-101, -99, -97, -94, -92,
-90, -88, -86, -83, -81, -78, -76, -73,
-71, -68, -66, -63, -60, -57, -55, -52,
-49, -46, -43, -40, -37, -34, -31, -28,
-25, -22, -19, -16, -12, -9, -6, -3
};
const float radius1 = 65.2, radius2 = 92.0, radius3 = 163.2, radius4 = 176.8,
centerx1 = 64.4, centerx2 = 46.4, centerx3 = 93.6, centerx4 = 16.4,
centery1 = 34.8, centery2 = 26.0, centery3 = 56.0, centery4 = -11.6;
float angle1 = 0.0, angle2 = 0.0, angle3 = 0.0, angle4 = 0.0;
long hueShift = 0;
/*******************************************/
/*************** Night Mode ****************/
struct TimerObject{
int hour, minute;
};
TimerObject clock_on = { 7, 0}; //daytime mode start time
TimerObject clock_off = {22, 0}; //night time mode start time
/*******************************************/
int Power_Mode = 1;
/***************************
* End Settings
**************************/
#define TZ_MN ((TZ)*60)
#define TZ_SEC ((TZ)*3600)
#define DST_SEC ((DST_MN)*60)
void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
listDir(fs, file.name(), levels - 1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void setReadyForWeatherUpdate();
void setup() {
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.println(WIFI_SSID);
WiFi.begin(WIFI_SSID,WIFI_PWD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
display.begin();
Serial.println();
Serial.print("Width: ");
Serial.println(display.width());
Serial.print("Height: ");
Serial.println(display.height());
heap_caps_check_integrity_all(true);
display.clearDisplay();
Serial.print("Pixel draw latency in us: ");
unsigned long start_timer=micros();
display.drawPixel(1,1,0);
unsigned long delta_timer=micros()-start_timer;
Serial.println(delta_timer);
Serial.print("Display update latency in us: ");
start_timer=micros();
display.clearDisplay();
delta_timer=micros()-start_timer;
Serial.println(delta_timer);
configTime(UTC_OFFSET * 3600, 0, NTP_SERVERS);
updateNTP(); // Init the NTP time
printTime(0); // print initial time time now.
yield();
// print each letter with a rainbow color
display.setCursor(0,0);
display.setTextColor(display.color444(15,0,0));
display.print('1');
display.setTextColor(display.color444(15,4,0));
display.print('6');
display.setTextColor(display.color444(15,15,0));
display.print('x');
display.setTextColor(display.color444(8,15,0));
display.print('3');
display.setTextColor(display.color444(0,15,0));
display.print('2');
display.setCursor(0,8);
display.setTextColor(display.color444(0,15,15));
display.print("*");
display.setTextColor(display.color444(0,8,15));
display.print('R');
display.setTextColor(display.color444(0,0,15));
display.print('G');
display.setTextColor(display.color444(8,0,15));
display.print("B");
display.setTextColor(display.color444(15,0,8));
display.println("*");
display.swapBuffer(false);
delay(1000);
heap_caps_check_integrity_all(true);
Serial.println(String(ESP.getFreeHeap()));
delay(100);
Serial.println(String(ESP.getFreeHeap()));
display.swapBuffer(false);
display.clearDisplay();
display.swapBuffer(false);
display.clearDisplay();
timeSinceLastWUpdate = millis()+1000L*UPDATE_INTERVAL_SECS;
}
void loop() {
if (millis() - modeSwitch > 20000UL) { //Switch modes every 5 mins (12000UL)
clock_mode++;
mode_changed = 1;
modeSwitch = millis();
if (clock_mode > MAX_CLOCK_MODE - 1)
clock_mode = 0;
DEBUGp("Switch mode to ");
DEBUGpln(clock_mode);
}
DEBUGp("in loop ");
//reset clock type clock_mode
switch (clock_mode) {
case 0:
actual_weather();
break;
case 1:
pong();
break;
case 2:
actual_weather();
break;
case 3:
normal_clock();
break;
case 4:
pong();
break;
case 5:
plasma();
break;
case 6:
marquee();
break;
default:
normal_clock();
break;
}
//if the mode hasn't changed, show the date
// pacClear();
if (mode_changed == 0) {
display_date();
pacClear();
}
else {
//the mode has changed, so don't bother showing the date, just go to the new mode.
mode_changed = 0; //reset mode flag.
}
}
//Runs pacman or other animation, refreshes weather data
void pacClear(){
DEBUGpln("in pacClear");
//refresh weather if we havent had it for 30 mins
//or the last time we had it, it was bad,
//or weve never had it before.
if((millis()>lastWeatherTime+1800000) || lastWeatherTime==0)
{
lastWeatherTime=millis();
getWeather();
}
if(!wasWeatherShownLast){
showWeather();
wasWeatherShownLast = true;
DEBUGpln("get Weather");
}
else{
wasWeatherShownLast = false;
pacMan();
}
}
//*****************Weather Stuff*********************
void quickWeather(){
getWeather();
showWeather();
yield();
delay(500);
}
void getWeather(){
DEBUGpln("in getWeather");
updateData();
}
void showWeather(){
byte dow = timeinfo->tm_wday;
String WCopy;
char dayname[4];
DEBUGpln("in showWeather");
for(int i = 0 ; i<MAX_FORECASTS; i++){
WCopy=String(forecasts[i].temp, 0);
DEBUGpln("HighTemp:");
DEBUGpln(WCopy);
DEBUGpln("Observationtime ");
DEBUGp(forecasts[i].observationTimeText);
DEBUGp(' ');
DEBUGpln(forecasts[i].observationTime);
DEBUGpln(fdow(forecasts[i].observationTime));
DEBUGpln(forecasts[i].main);
DEBUGpln(forecasts[i].rain);
WCopy.toCharArray(w_temp[i],WCopy.length()+1);
int numTemp = atoi(w_temp[i]);
//fix within range to generate colour value
if (numTemp<-14) numTemp=-10;
if (numTemp>34) numTemp =30;
//add 14 so it falls between 0 and 48
numTemp = numTemp +14;
//divide by 3 so value between 0 and 16
numTemp = numTemp / 3;
int tempColor;
if(numTemp<8){
tempColor = display.Color333(0,numTemp/2,7);
}
else{
tempColor = display.Color333(7,(7-numTemp/2) ,0);
}
cls();
String day= WDAY_NAMES[fdow(forecasts[i].observationTime)];
DEBUGpln(day);
day.toUpperCase();
day.toCharArray(dayname,3);
//Display the day on the top line.
if(i==0){ //TODAY
drawString(2,2,(char*)"Nu",51,display.Color333(1,1,1));
}
else{
drawString(2,2,dayname,51,display.Color333(0,1,0));
}
//put the temp underneath
boolean positive = !(w_temp[i][0]=='-');
for(int t=0; t<7; t++){
if(w_temp[i][t]=='-'){
display.drawLine(3,10,4,10,tempColor);
}
else if(!(w_temp[i][t]==0)){
vectorNumber(w_temp[i][t]-'0',t*4+2+(positive*2),8,tempColor,1,1);
}
}
display.swapBuffer(false);
display.swapBuffer(true);
WCopy=forecasts[i].iconMeteoCon;
DEBUGpln(WCopy);
WCopy.toCharArray(w_id[i],WCopy.length()+1);
DEBUGpln(w_id[i][0]);
drawWeatherIcon(16,0,w_id[i][0],forecasts[i].rain,forecasts[i].clouds);
}
}
void drawWeatherIcon(uint8_t x, uint8_t y, char id,uint8_t i_rain, uint8_t i_cloud){
unsigned long start = millis();
static int rain[12];
for(int r=0; r<13; r++){
//rain[r]=random(9,18);
rain[r]=random(9,15);
}
int rainColor = display.Color333(0,0,1);
byte intensity=i_rain; //mm per 3h
if (intensity>9)
intensity=9;
int deep =0;
boolean raining = false;
DEBUGp("in drawWeatherIcon... ");
DEBUGp(id);
DEBUGp(' ');
DEBUGp(intensity);
DEBUGp(' ');
DEBUGpln(i_cloud);
//translate night->day
if (id=='C')
id='B';
if (id=='4')
id='H';
if (id=='5')
id='N';
if (id=='%')
id='Y';
if (id=='8')
id='R';
if (id=='7')
id='Q';
if (id=='6')
id='P';
if (id=='#')
id='W';
while(millis()<start+2000){
switch(id){
case 'P':
//Thunder
display.fillRect(x,y,16,16,display.Color333(0,0,0));
display.drawBitmap(x,y,cloud_outline,16,16,display.Color333(1,1,1));
if(random(0,10)==3){
int pos = random(-5,5);
display.drawBitmap(pos+x,y,lightning,16,16,display.Color333(1,1,1));
}
raining = true;
break;
case 'Q':
//drizzle
display.fillRect(x,y,16,16,display.Color333(0,0,0));
display.drawBitmap(x,y,cloud,16,16,display.Color333(1,1,1));
raining=true;
intensity=1;
break;
case 'R':
//rain
display.fillRect(x,y,16,16,display.Color333(0,0,0));
if(intensity<3){
display.drawBitmap(x,y,cloud,16,16,display.Color333(1,1,1));
}
else{
display.drawBitmap(x,y,cloud_outline,16,16,display.Color333(1,1,1));
}
raining = true;
break;
case 'W':
//snow
rainColor = display.Color333(4,4,4);
display.fillRect(x,y,16,16,display.Color333(0,0,0));
deep = (millis()-start)/500;
if(deep>6) deep=6;
if(intensity<3){
display.drawBitmap(x,y,cloud,16,16,display.Color333(1,1,1));
display.fillRect(x,y+16-deep/2,16,deep/2,rainColor);
}
else{
display.drawBitmap(x,y,cloud_outline,16,16,display.Color333(1,1,1));
display.fillRect(x,y+16-(deep),16,deep,rainColor);
}
raining = true;
break;
case 'M':
//atmosphere
display.drawRect(x,y,16,16,display.Color333(1,0,0));
drawString(x+2,y+6,(char*)"FOG",51,display.Color333(1,1,1));
break;
case 'Y':
//cloud
display.fillRect(x,y,16,16,display.Color333(0,0,1));
if(id==800){
display.drawBitmap(x,y,big_sun,16,16,display.Color333(2,2,0));
}
else{
if(i_cloud<20){
display.drawBitmap(x,y,big_sun,16,16,display.Color333(2,2,0));
display.drawBitmap(x,y,cloud,16,16,display.Color333(1,1,1));
}
else{
if(i_cloud>=20){
display.drawBitmap(x,y,small_sun,16,16,display.Color333(1,1,0));
}
display.drawBitmap(x,y,cloud,16,16,display.Color333(1,1,1));
display.drawBitmap(x,y,cloud_outline,16,16,display.Color333(0,0,0));
}
}
break;
case 'X':
//extreme
display.fillRect(x,y,16,16,display.Color333(0,0,0));
display.drawRect(x,y,16,16,display.Color333(7,0,0));
if(id==906){
raining =true;
intensity=3;
display.drawBitmap(x,y,cloud,16,16,display.Color333(1,1,1));
};
break;
default:
display.fillRect(x,y,16,16,display.Color333(0,1,1));
display.drawBitmap(x,y,big_sun,16,16,display.Color333(2,2,0));
break;
}
if(raining){
for(int r = 0; r<13; r++){
display.drawPixel(x+r+2, rain[r]++, rainColor);
if(rain[r]==16) rain[r]=9;
//if(rain[r]==20) rain[r]=9;
}
}
display.swapBuffer(false);
yield(); //Give the background process some lovin'
delay(( 50 -( intensity * 10 )) < 0 ? 0: 50-intensity*10);
}
}
//*****************End Weather Stuff*********************
void scrollBigMessage(char *m){
display.setTextSize(1);
int l = (strlen(m)*-6) - (X_MAX+1);
for(int i = X_MAX+1; i > l; i--){
cls();
display.setCursor(i,1);
display.setTextColor(display.Color333(2,2,2));
display.print(m);
display.swapBuffer(false);
delay(50);
yield();
}
}
void scrollMessage(char* top, char* bottom ,uint8_t top_font_size,uint8_t bottom_font_size, uint16_t top_color, uint16_t bottom_color){
int l = ((strlen(top)>strlen(bottom)?strlen(top):strlen(bottom))*-5) - 32;
for(int i=32; i > l; i--){
if (mode_changed == 1 || mode_quick)
return;
cls();
drawString(i,2,top,top_font_size, top_color);
drawString(i,10,bottom, bottom_font_size, bottom_color);
display.swapBuffer(false);
delay(50);
yield();
}
}
void pacMan(){
#if defined (usePACMAN)
DEBUGpln("in pacMan");
if(powerPillEaten>0){
for(int i =(X_MAX+1)+(powerPillEaten*17); i>-17; i--){
long nowish = millis();
cls();
drawPac(i,0,-1);
if(powerPillEaten>0) drawScaredGhost(i-17,0);
if(powerPillEaten>1) drawScaredGhost(i-34,0);
if(powerPillEaten>2) drawScaredGhost(i-51,0);
if(powerPillEaten>3) drawScaredGhost(i-68,0);
display.swapBuffer(false);
while(millis()-nowish<50) yield(); //Give the background process some lovin'
}
powerPillEaten = 0;
}
else{
int hasEaten = 0;
int powerPill = random(0,5);
int numGhosts=random(0,4);
if(powerPill ==0){
if(numGhosts==0) numGhosts++;
powerPillEaten = numGhosts;
}
for(int i=-17; i<(X_MAX+1)+(numGhosts*17); i++){
cls();
long nowish = millis();
for(int j = 0; j<(X_MAX/5);j++){
if( j*5> i){
if(powerPill==0 && j==4){
display.fillCircle(j*5,8,2,display.Color333(7,3,0));
}
else{
display.fillRect(j*5,8,2,2,display.Color333(7,3,0));
}
}
}
if(i==19 && powerPill == 0) hasEaten=1;
drawPac(i,0,1);
if(hasEaten == 0){
if(numGhosts>0) drawGhost(i-17,0,display.Color333(3,0,3));
if(numGhosts>1) drawGhost(i-34,0,display.Color333(3,0,0));
if(numGhosts>2) drawGhost(i-51,0,display.Color333(0,3,3));
if(numGhosts>3) drawGhost(i-68,0,display.Color333(7,3,0));
}
else{
if(numGhosts>0) drawScaredGhost(i-17-(i-19)*2,0);
if(numGhosts>1) drawScaredGhost(i-34-(i-19)*2,0);
if(numGhosts>2) drawScaredGhost(i-51-(i-19)*2,0);
if(numGhosts>3) drawScaredGhost(i-68-(i-19)*2,0);
}
display.swapBuffer(false);
while(millis()-nowish<50) yield(); //Give the background process some lovin'
}
}
#endif //usePACMAN
}
#if defined (usePACMAN)
void drawPac(int x, int y, int z){
int c = display.Color333(3,3,0);
if(x>-16 && x<(X_MAX+1)){
if(abs(x)%4==0){
display.drawBitmap(x,y,(z>0?pac:pac_left),16,16,c);
}
else if(abs(x)%4==1 || abs(x)%4==3){
display.drawBitmap(x,y,(z>0?pac2:pac_left2),16,16,c);
}
else{
display.drawBitmap(x,y,(z>0?pac3:pac_left3),16,16,c);
}
}
}
void drawGhost( int x, int y, int color){
if(x>-16 && x<(X_MAX+1)){
if(abs(x)%8>3){
display.drawBitmap(x,y,blinky,16,16,color);
}
else{
display.drawBitmap(x,y,blinky2,16,16,color);
}
display.drawBitmap(x,y,eyes1,16,16,display.Color333(3,3,3));
display.drawBitmap(x,y,eyes2,16,16,display.Color333(0,0,7));
}
}
void drawScaredGhost( int x, int y){
if(x>-16 && x<(X_MAX+1)){
if(abs(x)%8>3){
display.drawBitmap(x,y,blinky,16,16,display.Color333(0,0,7));
}
else{
display.drawBitmap(x,y,blinky2,16,16,display.Color333(0,0,7));
}
display.drawBitmap(x,y,scared,16,16,display.Color333(7,3,2));
}
}
#endif //usePACMAN
void cls(){
display.clearDisplay(); //
}
void setReadyForWeatherUpdate() {
Serial.println("Setting readyForUpdate to true");
readyForWeatherUpdate = true;
}
void pong(){
DEBUGpln("in Pong");
display.setTextSize(1);
display.setTextColor(display.Color333(2, 2, 2));
float ballpos_x, ballpos_y;
float ballvel_x, ballvel_y;
int bat1_y = 5; //bat starting y positions
int bat2_y = 5;
int bat1_target_y = 5; //bat targets for bats to move to
int bat2_target_y = 5;
byte bat1_update = 1; //flags - set to update bat position
byte bat2_update = 1;
byte bat1miss, bat2miss; //flags set on the minute or hour that trigger the bats to miss the ball, thus upping the score to match the time.
byte restart = 1; //game restart flag - set to 1 initially to setup 1st game
cls();
//loop to display the clock for a set duration of SHOWCLOCK
for (int show = 0; show < SHOWCLOCK ; show++)
{
long showTime = millis();
now = dstAdjusted.time(&dstAbbrev);
timeinfo = localtime (&now);
while((millis() - showTime) < 6*showClock)
{
cls();
//draw pitch centre line
int adjust = 0;
if(timeinfo->tm_sec%2==0)adjust=1;
for (byte i = 0; i < (Y_MAX+1); i++) {
if ( i % 2 == 0 ) { //plot point if an even number
display.drawPixel((X_MAX+1)/2,i+adjust,display.Color333(0,4,0));
}
}
//main pong game loop
if (mode_changed == 1)
return;
if(mode_quick){
mode_quick = false;
display_date();
quickWeather();
pong();
return;
}
int ampm=0;
//update score / time
byte mins = timeinfo->tm_min;
byte hours = timeinfo->tm_hour;
if (hours > 12) {
hours = hours - ampm * 12;
}
if (hours < 1) {
hours = hours + ampm * 12;
}
char buffer[3];
itoa(hours,buffer,10);
//fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ".
if (hours < 10) {
buffer[1] = buffer[0];
buffer[0] = '0';
}
vectorNumber(buffer[0]-'0',((X_MAX+1)/2-2*4),1,display.Color333(1,1,1),1,1);
vectorNumber(buffer[1]-'0',((X_MAX+1)/2-1*4),1,display.Color333(1,1,1),1,1);
itoa(mins,buffer,10);
if (mins < 10) {
buffer[1] = buffer[0];