PowerTGS440

ESP8266 Morphing Clock v1.6

Mar 22nd, 2022 (edited)
1,492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 55.76 KB | None | 0 0
  1. /*
  2.  * Morphing Clock by Tomasz Majcher (Transline Group)
  3.  * version      : 1.6 beta (StartUp)
  4.  * date         : 22.03.2022
  5.  * e-mail       : [email protected]
  6.  * mobile       : +48 667082121
  7.  */
  8.  
  9. extern "C" char* sbrk(int incr);
  10.  
  11. /*
  12.  * History
  13.  *
  14.  * version 1.6      : modify -> refresh (interal 1 minute) display temp (before interval 1 hours)
  15.  *
  16.  * version 1.5      : modify -> speeding up the speed of the morphing animation
  17.  *
  18.  * version 1.4      : modify -> memory optymalization -> before -> use 307593kB (29% progmem) / use 29884kB RAM free 52036 kB RAM
  19.  *                                                    -> now    -> use 307585kB (29% progmem) / use 29876kB RAM free 52044 kB RAM
  20.                                                       -> safe   -> 216bytes RAM, 856bytes PROGMEM compare to version 1.1
  21.  *                                                    
  22.  * version 1.3      : modify -> memory optymalization -> before -> use 307609kB (29% progmem) / use 29908kB RAM free 52021 kB RAM
  23.  *                                                    -> now    -> use 307593kB (29% progmem) / use 29884kB RAM free 52036 kB RAM
  24.  *                                                    
  25.  * version 1.2      : modify -> memory optymalization -> before -> use 308441kB (29% progmem) / use 30092kB RAM free 51925 kB RAM
  26.  *                                                    -> now    -> use 307609kB (29% progmem) / use 29908kB RAM free 52012 kB RAM
  27.  *                                                    
  28.  * version 1.1      : repair -> debug & find & bug
  29.  * version 1.0      : test
  30.  * version 0.9      : build -> add DHT11 sensor and tested : build buffor for humidity & devPoint
  31.  * version 0.8      : build -> add DHT11 sensor and tested : show temperature on PxMatrix
  32.  * version 0.7      : test
  33.  * version 0.6      : build
  34.  * version 0.5      : build
  35.  * version 0.4      : build
  36.  * version 0.3      : build
  37.  */
  38.  
  39. #define ARRAY_SIZE(a)   (sizeof(a) / sizeof((a)[0]))
  40.  
  41. #define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
  42. #define F(string_literal) (FPSTR(PSTR(string_literal)))
  43.  
  44. /***************************************************************************************************************/
  45. /*!
  46.     @define   macro
  47.     @create   macro-time
  48. */
  49. /***************************************************************************************************************/
  50.  
  51. #define TIME_01S      1000                                     // 1 sekunda
  52. #define TIME_10S     10000                                     // 10 sekund
  53. #define TIME_01M     60000                                     // 1 minuta
  54. #define TIME_05M    360000                                     // 5 minut
  55. #define TIME_10M    600000                                     // 10 minut
  56. #define TINE_01H   3600000                                     // 1 godzina
  57.  
  58. /***************************************************************************************************************/
  59. /*!
  60.     @library  PxMatrix.h
  61.     @include  library, font
  62.     @define   pin, width, height
  63.     @create   object PxMatrix
  64. */
  65. /***************************************************************************************************************/
  66.  
  67. #include <PxMatrix.h>                                       // załączenie biblioteki
  68.  
  69. #define P_LAT 16                                            // definicja pin : P_LAT
  70. #define P_A 5                                               // definicja pin : P_A
  71. #define P_B 4                                               // definicja pin : P_B
  72. #define P_C 15                                              // definicja pin : P_C
  73. #define P_D 12                                              // definicja pin : P_D
  74. #define P_E 0                                               // definicja pin : P_E
  75. #define P_OE 2                                              // definicja pin : P_OE
  76.  
  77. #define matrix_width 64                                     // definicja  : szerokość wyświetlacza
  78. #define matrix_height 32                                    // definicja  : wysokość wyświetlacza
  79.  
  80. const uint8_t display_draw_time=10;                         // zmienna : display_draw_time
  81. const byte animSpeed = 15;                                  // zmienna : prędkość animacji (morphing digit)
  82.  
  83. PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);        // utwórz obiekt display klasy PxMatrix
  84.  
  85. /***************************************************************************************************************/
  86. /*!
  87.     @library  Ticker.h
  88.     @include  library
  89.     @define   function
  90. */
  91. /***************************************************************************************************************/
  92.  
  93. #include <Ticker.h>
  94.  
  95. Ticker display_ticker;
  96.  
  97. void display_updater();                                     // definicja funkcji
  98. void display_update_enable(bool is_enable);                 // definicja funkcji
  99.  
  100. /***************************************************************************************************************/
  101. /*!
  102.     @value    Digit    
  103.     @class    Digit
  104. */
  105. /***************************************************************************************************************/
  106.  
  107. const byte sA = 0;
  108. const byte sB = 1;
  109. const byte sC = 2;
  110. const byte sD = 3;
  111. const byte sE = 4;
  112. const byte sF = 5;
  113. const byte sG = 6;
  114. const int segHeight = 6;
  115. const int segWidth = segHeight;
  116. const uint16_t height = 31;
  117. const uint16_t width = 63;
  118.  
  119. const byte digitBits[] =
  120. {
  121.     B11111100, // 0 ABCDEF--
  122.     B01100000, // 1 -BC-----
  123.     B11011010, // 2 AB-DE-G-
  124.     B11110010, // 3 ABCD--G-
  125.     B01100110, // 4 -BC--FG-
  126.     B10110110, // 5 A-CD-FG-
  127.     B10111110, // 6 A-CDEFG-
  128.     B11100000, // 7 ABC-----
  129.     B11111110, // 8 ABCDEFG-
  130.     B11110110, // 9 ABCD_FG-
  131. };
  132.  
  133. uint16_t black;
  134.  
  135. /***************************************************************************************************************/
  136. /*!
  137.     @class    Digit    
  138. */
  139. /***************************************************************************************************************/
  140.  
  141. class Digit
  142. {
  143.     public:
  144.         Digit(PxMATRIX* d, byte value, uint16_t xo, uint16_t yo, uint16_t color);
  145.         void Draw(byte value);
  146.         void Morph(byte newValue);
  147.         byte Value();
  148.         void DrawColon(uint16_t c);
  149.    
  150.     private:
  151.         PxMATRIX* _display;
  152.         byte _value;
  153.         uint16_t _color;
  154.         uint16_t xOffset;
  155.         uint16_t yOffset;        
  156.  
  157.         void drawPixel(uint16_t x, uint16_t y, uint16_t c);
  158.         void drawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t c);
  159.         void drawLine(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2, uint16_t c);
  160.         void drawSeg(byte seg);
  161.         void Morph2();
  162.         void Morph3();
  163.         void Morph4();
  164.         void Morph5();
  165.         void Morph6();
  166.         void Morph7();
  167.         void Morph8();
  168.         void Morph9();
  169.         void Morph0();
  170.         void Morph1();
  171. };
  172.  
  173. /***************************************************************************************************************/
  174. /*!
  175.     @library  Digit.h
  176.     @include  library
  177.     @define  
  178.     @create   object
  179. */
  180. /***************************************************************************************************************/
  181.  
  182. Digit digit0(&display, 0, 63 - 1 - 9*1, 8, display.color565(0, 0, 255));
  183. Digit digit1(&display, 0, 63 - 1 - 9*2, 8, display.color565(0, 0, 255));
  184. Digit digit2(&display, 0, 63 - 4 - 9*3, 8, display.color565(0, 0, 255));
  185. Digit digit3(&display, 0, 63 - 4 - 9*4, 8, display.color565(0, 0, 255));
  186. Digit digit4(&display, 0, 63 - 7 - 9*5, 8, display.color565(0, 0, 255));
  187. Digit digit5(&display, 0, 63 - 7 - 9*6, 8, display.color565(0, 0, 255));
  188.  
  189. /***************************************************************************************************************/
  190. /*!
  191.     @library  ESP8266WiFi.h
  192.     @include  library
  193.     @define   ssid, password
  194.     @create   object
  195. */
  196. /***************************************************************************************************************/
  197.  
  198. #include <ESP8266WiFi.h>                                          // biblioteka do obsługi wi-fi
  199.  
  200. const char *ssid     = "OFFICE_SERV_02";                                  // network wifi ssid  
  201. const char *password = "xxxxxxxxxxxxxxxxxxx";                             // network wifi password
  202.  
  203. unsigned long previousMillis = 0;                                 // re-conect Wi-FI
  204. const unsigned long interval = 30000;                                   // re-conect Wi-FI
  205.  
  206. /***************************************************************************************************************/
  207. /*!
  208.     @library      TaskScheduler.h
  209.     @include      library
  210.     @declaration  function
  211.     @create       object
  212. */
  213. /***************************************************************************************************************/
  214.  
  215. #include <TaskScheduler.h>                                                // scheluder
  216.  
  217. void Task0Callback();                                                     // funkcja dla task_0    
  218. void Task1Callback();                                                     // funkcja dla task_1    
  219. void Task2Callback();                                                     // funkcja dla task_2    
  220. void Task3Callback();                                                     // funkcja dla task_3    
  221. void Task4Callback();                                                     // funkcja dla task_4    
  222.  
  223. Task task_0(  TIME_01S,  TASK_FOREVER, &Task0Callback);                   // task_0 - co 1 sekundę
  224. Task task_1(  TIME_01M,  TASK_FOREVER, &Task1Callback);                   // task_1 - co 1 sekundę  
  225. Task task_2(  TIME_01S,  TASK_FOREVER, &Task2Callback);                   // task_2 - co 1 sekundę  
  226. Task task_3(  TIME_10M,  TASK_FOREVER, &Task3Callback);                   // task_3 - co 1 sekundę
  227. Task task_4(  TIME_05M,  TASK_FOREVER, &Task4Callback);                   // task_4 - co 5 minut                                                                                                      
  228.  
  229. Scheduler runner;      
  230.  
  231. /***************************************************************************************************************/
  232. /*!
  233.     @library      TimeLib.h, WifiUdp.h, NTPClient_Generic.h
  234.     @include      library
  235.     @declaration  timefunction
  236.     @create       object
  237. */
  238. /***************************************************************************************************************/
  239.  
  240. #include <NTPClient_Generic.h>                                    // NTP klient (Time)
  241. #include <WiFiUdp.h>                                              // UDP dla NTP (Time)
  242. #include <TimeLib.h>                                              // TimeLib
  243.  
  244. WiFiUDP ntpUDP;  
  245.  
  246. const char timeServer[] = "0.pl.pool.ntp.org";
  247.    
  248. #define TIME_ZONE_OFFSET_HRS            1                        // Europe, Poland (2)
  249. #define NTP_UPDATE_INTERVAL_MS          60000L                   // update interval
  250.  
  251. NTPClient timeClient(ntpUDP, timeServer, (3600 * TIME_ZONE_OFFSET_HRS), NTP_UPDATE_INTERVAL_MS);                                    
  252.  
  253. bool F_TimeUpdate = false;                                       // flag to update (second)
  254. unsigned long prevEpoch;
  255. byte prevhh;
  256. byte prevmm;
  257. byte prevss;
  258.  
  259. /***************************************************************************************************************/
  260. /*!
  261.     @library      dht11.h
  262.     @include      library
  263.     @declaration  temperature, humidity
  264.     @create       object
  265. */
  266. /***************************************************************************************************************/
  267.  
  268. #include <dht11.h>
  269. #define DHT_PIN 0
  270.  
  271. dht11 DHT11;
  272.  
  273.  
  274. /***************************************************************************************************************/
  275. /*
  276.     @declaration   function
  277. */
  278. /***************************************************************************************************************/
  279.  
  280. void statWiFi();
  281. void initWiFi();
  282. void reconectWifi();
  283. void SerialTypeWriter(const String & message, unsigned int wait);
  284. void ShowInfo();                                                        // pokaż INTRO
  285. void PM_ShowTemperature();
  286.  
  287.  
  288. /***************************************************************************************************************/
  289. /*!
  290.     @colour   standard    
  291. */
  292. /***************************************************************************************************************/
  293.  
  294. const uint16_t myRED = display.color565(255, 0, 0);
  295. const uint16_t myGREEN = display.color565(0, 255, 0);
  296. const uint16_t myBLUE = display.color565(0, 0, 255);
  297. const uint16_t myWHITE = display.color565(255, 255, 255);
  298. const uint16_t myYELLOW = display.color565(255, 255, 0);
  299. const uint16_t myCYAN = display.color565(0, 255, 255);
  300. const uint16_t myMAGENTA = display.color565(255, 0, 255);
  301. const uint16_t myBLACK = display.color565(0, 0, 0);
  302. const uint16_t mySha = display.color565(54,47,36);
  303. const uint16_t myROSE = display.color565(255,0,127);
  304.  
  305. const uint16_t myCOLORS[8]  = {myRED,myGREEN,myBLUE,myWHITE,myYELLOW,myCYAN,myMAGENTA,myBLACK};
  306. const uint16_t myCOLORS2[9] = {myRED, myGREEN, myWHITE, myMAGENTA, myBLUE, myYELLOW, myCYAN, mySha, myROSE};
  307.  
  308. /***************************************************************************************************************/
  309. /*!
  310.     @colour   Blue    
  311. */
  312. /***************************************************************************************************************/
  313.  
  314. const uint16_t myBlue0 = display.color565(0,   0, 255);
  315. const uint16_t myBlue1 = display.color565(0,  30, 255);
  316. const uint16_t myBlue2 = display.color565(0,  60, 255);
  317. const uint16_t myBlue3 = display.color565(0,  90, 255);
  318. const uint16_t myBlue4 = display.color565(0, 120, 255);
  319. const uint16_t myBlue5 = display.color565(0, 150, 255);
  320. const uint16_t myBlue6 = display.color565(0, 180, 255);
  321. const uint16_t myBlue7 = display.color565(0, 210, 255);
  322. const uint16_t myBlue8 = display.color565(0, 250, 255);
  323.  
  324. const uint16_t myBlue[9] = {myBlue0, myBlue1, myBlue2, myBlue3, myBlue4, myBlue5, myBlue6, myBlue7, myBlue8};
  325.  
  326. /***************************************************************************************************************/
  327. /*!
  328.     @colour   Dark
  329. */    
  330. /***************************************************************************************************************/
  331.  
  332. const uint16_t myDark0 = display.color565(20, 20, 20);
  333. const uint16_t myDark1 = display.color565(25, 25, 25);
  334. const uint16_t myDark2 = display.color565(30, 30, 30);
  335. const uint16_t myDark3 = display.color565(35, 35, 35);
  336. const uint16_t myDark4 = display.color565(40, 40, 40);
  337. const uint16_t myDark5 = display.color565(45, 45, 45);
  338. const uint16_t myDark6 = display.color565(50, 50, 50);
  339. const uint16_t myDark7 = display.color565(55, 55, 55);
  340. const uint16_t myDark8 = display.color565(60, 60, 60);
  341.  
  342. const uint16_t myDark[9] = {myDark0, myDark1, myDark2, myDark3, myDark4, myDark5, myDark6, myDark7, myDark8};
  343.  
  344. /***************************************************************************************************************/
  345. /*!
  346.     @colour   DarkRed
  347. */
  348. /***************************************************************************************************************/
  349.  
  350. const uint16_t myDarkRed0 = display.color565(20, 1,   8);
  351. const uint16_t myDarkRed1 = display.color565(31, 1,  12);
  352. const uint16_t myDarkRed2 = display.color565(36, 1,  14);
  353. const uint16_t myDarkRed3 = display.color565(41, 1,  16);
  354. const uint16_t myDarkRed4 = display.color565(46, 1,  18);
  355. const uint16_t myDarkRed5 = display.color565(50, 1,  20);
  356. const uint16_t myDarkRed6 = display.color565(54, 1,  24);
  357. const uint16_t myDarkRed7 = display.color565(58, 1,  28);
  358. const uint16_t myDarkRed8 = display.color565(64, 1,  32);
  359.  
  360. const uint16_t myDarkRed[9] = {myDarkRed0, myDarkRed1, myDarkRed2, myDarkRed3, myDarkRed4, myDarkRed5, myDarkRed6, myDarkRed7, myDarkRed8};
  361.  
  362. /***************************************************************************************************************/
  363. /*!
  364.     @colour   DarkSea  
  365. */
  366. /***************************************************************************************************************/
  367. const uint16_t myDarkSea0 = display.color565(1, 10,  32);
  368. const uint16_t myDarkSea1 = display.color565(1, 14,  36);
  369. const uint16_t myDarkSea2 = display.color565(1, 16,  38);
  370. const uint16_t myDarkSea3 = display.color565(1, 20,  40);
  371. const uint16_t myDarkSea4 = display.color565(1, 24,  42);
  372. const uint16_t myDarkSea5 = display.color565(1, 28,  44);
  373. const uint16_t myDarkSea6 = display.color565(1, 32,  46);
  374. const uint16_t myDarkSea7 = display.color565(1, 36,  48);
  375. const uint16_t myDarkSea8 = display.color565(1, 40,  50);
  376.  
  377. const uint16_t myDarkSea[9] = {myDarkSea0, myDarkSea1, myDarkSea2, myDarkSea3, myDarkSea4, myDarkSea5, myDarkSea6, myDarkSea7, myDarkSea8};
  378.  
  379. /***************************************************************************************************************/
  380. /*!
  381.     @definition   Weekday, Month
  382. */
  383. /***************************************************************************************************************/
  384.  
  385. const char* Weekday[7] = {"Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"};
  386. const char* Months []= {"Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  387.  
  388. /***************************************************************************************************************/
  389. /*!
  390.     @define   Serial Setup & Language Setup
  391. */
  392. /***************************************************************************************************************/
  393.  
  394. #define LANGUAGE 0                                            // 0 (Polish), 1 (English), 2 (Germany)
  395.                                                                
  396. #if LANGUAGE == 0                                                
  397.     #define POLISH 1
  398.     #define ENGLISH 0
  399.     #define GERMANY 0                                          
  400. #endif
  401.    
  402. #if LANGUAGE == 1                                                      
  403.     #define POLISH 0                                        
  404.     #define ENGLISH 1
  405.     #define GERMANY 0
  406. #endif
  407.  
  408. #if LANGUAGE == 2
  409.     #define POLISH 0
  410.     #define ENGLISH 0
  411.     #define GERMANY 1
  412. #endif      
  413.  
  414. #define SERIAL true
  415. #define SerialSpeed 57600
  416.  
  417. #define DEBUG true
  418.  
  419. /***************************************************************************************************************/
  420. /*    
  421.     @declaration    function
  422.     @function       display_updater()
  423.     @function       display_update_enable(bool is_enable)
  424. */
  425. /***************************************************************************************************************/
  426.  
  427. void display_updater()
  428. {
  429.     display.display(display_draw_time);
  430. }
  431.  
  432. void display_update_enable(bool is_enable)
  433. {
  434.     if (is_enable)
  435.     {
  436.         display_ticker.attach(0.004, display_updater);
  437.     }
  438.     else
  439.     {
  440.         display_ticker.detach();
  441.     }
  442. }
  443.  
  444. /***************************************************************************************************************/
  445. /*    
  446.     @struct         TIME_DATA    
  447. */
  448. /***************************************************************************************************************/
  449.  
  450. struct TIME_DATA
  451. {
  452.       int Hour = 0;
  453.       int Minute  = 0;
  454.       int Second = 0;    
  455.       int DayOfTheWeek = 0;
  456.       int DayOfTheMonth = 0;
  457.       int Day = 0;
  458.       int Month = 0;
  459.       int Year = 0;
  460.       String formated_date = "";
  461. }
  462. MyClock;
  463.  
  464. /***************************************************************************************************************/
  465. /*    
  466.     @struct         HomeClimat  
  467. */
  468. /***************************************************************************************************************/
  469.  
  470. struct  HOME_CLIMAT
  471. {
  472.     float  inside_temperature  = 0;
  473.     int    inside_humidity     = 0;
  474.     float  inside_devpoint     = 0;
  475.     char   temp_char_buffer[20];                        // bufor
  476.     String buf_temperature = "no data";                 // bufor
  477.     String buf_humidity    = "no data";                 // bufor
  478.     String buf_devpoint    = "no data";                 // bufor
  479. }
  480. mydht;
  481.  
  482. /***************************************************************************************************************/
  483. /*    
  484.     @declaration    DAY PL, EN, DE    
  485. */
  486. /***************************************************************************************************************/
  487.  
  488. #if POLISH
  489.       const char Day_0 [] = "Niedziela";
  490.       const char Day_1 [] = "Poniedzialek";
  491.       const char Day_2 [] = "Wtorek";
  492.       const char Day_3 [] = "Sroda";
  493.       const char Day_4 [] = "Czwartek";
  494.       const char Day_5 [] = "Piatek";
  495.       const char Day_6 [] = "Sobota";
  496. #endif
  497.  
  498. #if ENGLISH
  499.       const char Day_0 [] = "Sunday";
  500.       const char Day_1 [] = "Monday";
  501.       const char Day_2 [] = "Tuesday";
  502.       const char Day_3 [] = "Wednesday";
  503.       const char Day_4 [] = "Thursday";
  504.       const char Day_5 [] = "Friday";
  505.       const char Day_6 [] = "Saturday";
  506. #endif
  507.  
  508. #if GERMANY
  509.       const char Day_0 [] = "Sonntag";
  510.       const char Day_1 [] = "Montag";
  511.       const char Day_2 [] = "Dienstag";
  512.       const char Day_3 [] = "Mittwoch";
  513.       const char Day_4 [] = "Donnerstag";
  514.       const char Day_5 [] = "Freitag";
  515.       const char Day_6 [] = "Samstag";
  516. #endif
  517.  
  518. const char * const DAY[] = { Day_0, Day_1, Day_2, Day_3, Day_4, Day_5, Day_6 }; // dni tygodnia [0..6]
  519.  
  520. /***************************************************************************************************************/
  521. /*    
  522.     @declaration    MONTH PL, EN, DE    
  523. */
  524. /***************************************************************************************************************/
  525.  
  526. #if POLISH
  527.       const char MONTH_0  [] = "NULL";
  528.       const char MONTH_1  [] = "Styczen";
  529.       const char MONTH_2  [] = "Luty";
  530.       const char MONTH_3  [] = "Marzec";
  531.       const char MONTH_4  [] = "Kwiecien";
  532.       const char MONTH_5  [] = "Maj";
  533.       const char MONTH_6  [] = "Czerwiec";
  534.       const char MONTH_7  [] = "Lipiec";
  535.       const char MONTH_8  [] = "Sierpien";
  536.       const char MONTH_9  [] = "Wrzesien";
  537.       const char MONTH_10 [] = "Pazdziernik";
  538.       const char MONTH_11 [] = "Listopad";
  539.       const char MONTH_12 [] = "Grudzien";
  540. #endif
  541.  
  542. #if ENGLISH
  543.       const char MONTH_0  [] = "NULL";
  544.       const char MONTH_1  [] = "January";
  545.       const char MONTH_2  [] = "February";
  546.       const char MONTH_3  [] = "March";
  547.       const char MONTH_4  [] = "April";
  548.       const char MONTH_5  [] = "May";
  549.       const char MONTH_6  [] = "June";
  550.       const char MONTH_7  [] = "July";
  551.       const char MONTH_8  [] = "August";
  552.       const char MONTH_9  [] = "September";
  553.       const char MONTH_10 [] = "October";
  554.       const char MONTH_11 [] = "November";
  555.       const char MONTH_12 [] = "December";
  556. #endif
  557.  
  558. #if GERMANY
  559.       const char MONTH_0  [] = "NULL";
  560.       const char MONTH_1  [] = "Januar";
  561.       const char MONTH_2  [] = "Februar";
  562.       const char MONTH_3  [] = "März";
  563.       const char MONTH_4  [] = "April";
  564.       const char MONTH_5  [] = "Mai";
  565.       const char MONTH_6  [] = "Juni";
  566.       const char MONTH_7  [] = "Juli";
  567.       const char MONTH_8  [] = "August";
  568.       const char MONTH_9  [] = "September";
  569.       const char MONTH_10 [] = "Oktober";
  570.       const char MONTH_11 [] = "November";
  571.       const char MONTH_12 [] = "Dezember";
  572. #endif
  573.      
  574. const char * const MONTH[] = { MONTH_0, MONTH_1, MONTH_2, MONTH_3, MONTH_4, MONTH_5, MONTH_6,
  575.                                MONTH_7, MONTH_8, MONTH_9, MONTH_10, MONTH_11, MONTH_12 };
  576.  
  577.  
  578. /***************************************************************************************************************/
  579. /*    
  580.     @definition     Task0Callback
  581.     @interval       1 sekunda
  582.     @task           morphing clock
  583. */
  584. /***************************************************************************************************************/
  585.  
  586. void Task0Callback()
  587. {
  588.    
  589. }
  590.  
  591. /***************************************************************************************************************/
  592. /*    
  593.     @definition    Task1Callback
  594. */
  595. /***************************************************************************************************************/
  596.  
  597. void Task1Callback()
  598. {
  599.     #if SERIAL
  600.         #if ENGLISH
  601.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK1] Hello from Task1Callback :-)") );
  602.         #endif
  603.         #if POLISH
  604.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK1] Uruchomiono Task1Callback :-)") );
  605.         #endif
  606.         #if GERMANY
  607.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK1] Sie sind in Task1Callback :-)") );
  608.         #endif
  609.     #endif
  610.    
  611.     #if SERIAL
  612.         Serial.printf_P( PSTR( "\n\n[ESP] [TASK1] [Memory Free]     : %u [kB]" ), ESP.getFreeHeap());      
  613.         Serial.printf_P( PSTR( "\n[ESP] [TASK1] [CPU frequency]   : %u [MHz]" ),ESP.getCpuFreqMHz());  
  614.         Serial.printf_P( PSTR( "\n[ESP] [TASK1] [WiFi IP]         : " )); Serial.print(WiFi.localIP() );
  615.        
  616.         #if POLISH
  617.            Serial.printf("\n[ESP] [TASK1] [Local Time]      : ");
  618.            Serial.print(String() + timeClient.getStrHours() + ":"
  619.                                    + timeClient.getStrMinutes() + ":"
  620.                                    + timeClient.getStrSeconds() + " "
  621.                                    + DAY[timeClient.WeekDay()-1] + " "                                  
  622.                                    + timeClient.getDay() + "/"
  623.                                    + timeClient.getMonth() + "/"
  624.                                    + timeClient.getYear());          
  625.         #endif        
  626.         #if ENGLISH
  627.            Serial.printf("\n[ESP] [TASK1] [Local Time]      : ");
  628.            Serial.print(String() + timeClient.getStrHours() + ":"
  629.                                    + timeClient.getStrMinutes() + ":"
  630.                                    + timeClient.getStrSeconds() + " "
  631.                                    + DAY[timeClient.WeekDay()-1] + " "
  632.                                    + timeClient.getDay() + "/"
  633.                                    + timeClient.getMonth() + "/"
  634.                                    + timeClient.getYear());          
  635.        #endif        
  636.        #if GERMANY
  637.            Serial.printf("\n[ESP] [TASK1] [Local Time]      : ");
  638.            Serial.print(String() + timeClient.getStrHours() + ":"
  639.                                    + timeClient.getStrMinutes() + ":"
  640.                                    + timeClient.getStrSeconds() + " "
  641.                                    + DAY[timeClient.getWeek()-1] + " "
  642.                                    + timeClient.getDay() + "/"
  643.                                    + timeClient.getMonth() + "/"
  644.                                    + timeClient.getYear());          
  645.        #endif                              
  646.     #endif        
  647. }
  648.  
  649. /***************************************************************************************************************/
  650. /*    
  651.     @definition     Task2Callback
  652.     @interval       1 seconds
  653.     @function       update time only
  654. */
  655. /***************************************************************************************************************/
  656.  
  657. void Task2Callback()
  658. {
  659.     timeClient.update();                                        // update time
  660.      
  661.     if (timeClient.updated())
  662.     {
  663.         F_TimeUpdate = true;
  664.     }
  665.     else
  666.     {
  667.         #if ENGLISH
  668.             Serial.printf_P( PSTR ("\n[ESP] [TASK2] [Time Update]     : Wait"));
  669.         #endif
  670.         #if POLISH
  671.             Serial.printf_P( PSTR ("\n[ESP] [TASK2] [Time Update]     : Czekaj"));
  672.         #endif
  673.         #if GERMANY
  674.             Serial.printf_P( PSTR ("\n[ESP] [TASK2] [Time Update]     : Warten"));
  675.         #endif
  676.         F_TimeUpdate = false;                            
  677.     }
  678.      
  679. }
  680.  
  681. /***************************************************************************************************************/
  682. /*    
  683.     @definition     Task3Callback
  684.     interval       10 minuts
  685.    
  686. */
  687. /***************************************************************************************************************/
  688.  
  689. void Task3Callback()
  690. {
  691.     #if SERIAL
  692.         #if ENGLISH
  693.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK3] Hello from Task3Callback :-)") );
  694.         #endif
  695.         #if POLISH
  696.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK3] Uruchomiono Task3Callback :-)") );
  697.         #endif
  698.         #if GERMANY
  699.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK3] Sie sind in Task3Callback :-)") );
  700.         #endif
  701.     #endif
  702.  
  703.     if (timeClient.updated())
  704.     {
  705.  
  706.         /*          
  707.         *  tworzy sformatowaną datę (format String) w postaci dd/mm/yyyy
  708.         */
  709.  
  710.         if( timeClient.getDay() < 10 ) MyClock.formated_date = "0" + String(timeClient.getDay()) + "/";
  711.         else                           MyClock.formated_date = String(timeClient.getDay()) + "/";
  712.  
  713.         if( timeClient.getMonth() < 10 )  MyClock.formated_date += "0" + String(timeClient.getMonth()) + "/";
  714.         else                              MyClock.formated_date += String(timeClient.getMonth()) + "/";
  715.            
  716.         MyClock.formated_date += String(timeClient.getYear());          
  717.  
  718.         #if SERIAL
  719.             #if ENGLISH
  720.                 Serial.printf_P( PSTR ("\n[ESP] [TASK4] Create Formated Date : %s "), MyClock.formated_date.c_str());
  721.             #endif
  722.             #if POLISH
  723.                 Serial.printf_P( PSTR ("\n[ESP] [TASK4] Utworzono Sformatowaną Datę :%s "), MyClock.formated_date.c_str());
  724.             #endif
  725.         #endif  
  726.          
  727.      }
  728. }
  729.  
  730. /***************************************************************************************************************/
  731. /*    
  732.     @definition    Task4Callback
  733.     @function      get & show temperature & humidity
  734. */
  735. /***************************************************************************************************************/
  736.  
  737. void Task4Callback()
  738. {
  739.    #if SERIAL
  740.         #if ENGLISH
  741.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK4] Hello from Task4Callback :-)") );
  742.         #endif
  743.         #if POLISH
  744.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK4] Uruchomiono Task4Callback :-)") );
  745.         #endif
  746.         #if GERMANY
  747.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK4] Sie sind in Task4Callback :-)") );
  748.         #endif
  749.     #endif
  750.  
  751.     int chk = DHT11.read();
  752.  
  753.     #if SERIAL
  754.         #if ENGLISH
  755.             Serial.printf_P( PSTR ("\nRead DHT11 sensor : ") );    
  756.         #endif
  757.         #if POLISH
  758.             Serial.printf_P( PSTR ("\nOdczyt z sensora DHT11 : ") );
  759.         #endif
  760.         #if GERMANY
  761.             Serial.printf_P( PSTR ("\nSensorwert DHT11 : ") );
  762.         #endif
  763.     #endif
  764.  
  765.     #if SERIAL
  766.         switch (chk)
  767.         {
  768.             case  0:
  769.                     Serial.printf_P( PSTR ("OK") );                    
  770.                     break;
  771.            
  772.             case -1:
  773.                 #if ENGLISH
  774.                     Serial.printf_P( PSTR ("Checksum error") ); break;
  775.                 #endif                
  776.                 #if POLISH
  777.                     Serial.printf_P( PSTR ("Błąd sumy kontrolnej") ); break;
  778.                 #endif
  779.                 #if GERMANY
  780.                     Serial.printf_P( PSTR ("Prüfsummenfehler") ); break;
  781.                 #endif
  782.            
  783.             case -2:
  784.                 #if ENGLISH
  785.                     Serial.printf_P( PSTR ("Time out error") ); break;
  786.                 #endif                
  787.                 #if POLISH
  788.                     Serial.printf_P( PSTR ("Błąd przekroczenia limitu czasu") ); break;
  789.                 #endif
  790.                 #if GERMANY
  791.                     Serial.printf_P( PSTR ("Zeitüberschreitungsfehler") ); break;
  792.                 #endif            
  793.            
  794.             default:
  795.                 #if ENGLISH
  796.                     Serial.printf_P( PSTR ("Unknown error") ); break;
  797.                 #endif                
  798.                 #if POLISH
  799.                     Serial.printf_P( PSTR ("Nieznany błąd") ); break;
  800.                 #endif
  801.                 #if GERMANY
  802.                     Serial.printf_P( PSTR ("Unbekannter Fehler") ); break;
  803.                 #endif      
  804.         }   // end switch
  805.     #endif
  806.  
  807.     /*
  808.      *  copy DHT11 temperature, humidity, devPoint to data in structure mydht
  809.      *  kopiowanie DHT 11 temperatura, wilgotność, punkt zerowy do danych w strukturze mydht
  810.      */
  811.      
  812.     mydht.inside_temperature = (float)DHT11.temperature;
  813.     mydht.inside_humidity = DHT11.humidity;
  814.     mydht.inside_devpoint = (float)DHT11.dewPoint();    
  815.  
  816.     /*
  817.      *  jeśli włączony SERIAL wydrukuj odczyty na terminalu SERIAL
  818.      *  if SERIAL is TRUE print sensor-read on terminal SERIAL
  819.      */
  820.  
  821.     #if SERIAL
  822.         #if ENGLISH
  823.             Serial.printf_P( PSTR ("\nINSIDE Temperature : %0.1f °C"), mydht.inside_temperature );
  824.             Serial.printf_P( PSTR ("\nINSIDE Humidity    : %d %%"), mydht.inside_humidity );
  825.             Serial.printf_P( PSTR ("\nINSIDE DevPoint    : %0.1f °C"), mydht.inside_devpoint );
  826.         #endif
  827.         #if POLISH
  828.             Serial.printf_P( PSTR ("\nWEWNĄTRZ Temperatura : %0.1f °C"), mydht.inside_temperature );
  829.             Serial.printf_P( PSTR ("\nWEWNĄTRZ Wilgotność  : %d %%"), mydht.inside_humidity );
  830.             Serial.printf_P( PSTR ("\nWEWNĄTRZ Punkt ZERO  : %0.1f °C"), mydht.inside_devpoint );
  831.         #endif
  832.         #if GERMANY
  833.             Serial.printf_P( PSTR ("\nInnen temperatur                   : %0.1f °C"), mydht.inside_temperature );
  834.             Serial.printf_P( PSTR ("\ninnere Feuchtigkeit                : %d %%"), mydht.inside_humidity );
  835.             Serial.printf_P( PSTR ("\ninnerhalb des Entwicklungspunktes  : %0.1f °C"), mydht.inside_devpoint );
  836.         #endif      
  837.     #endif
  838.    
  839.     /*
  840.      *  konwersja float (temperature) do char[20] buffer
  841.      *  rzutowanie typów char[20] buffer do String -> mydht.buf_temperature
  842.      */
  843.      
  844.     snprintf(mydht.temp_char_buffer, sizeof mydht.temp_char_buffer, "%0.1fC", mydht.inside_temperature);
  845.     mydht.buf_temperature = "Temp:" + String(mydht.temp_char_buffer);
  846.  
  847.     #if DEBUG
  848.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.temp_char_buffer : %s"), mydht.temp_char_buffer);
  849.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.buf_temperature  : %s"), mydht.buf_temperature);
  850.     #endif
  851.  
  852.     /*
  853.      *  konwersja float (humidity) do char[20] buffer
  854.      *  rzutowanie typów char[20] buffer do String -> mydht.buf_temperature
  855.      */
  856.      
  857.     snprintf(mydht.temp_char_buffer, sizeof mydht.temp_char_buffer, "%d%%", mydht.inside_humidity);
  858.     mydht.buf_humidity = "Humi:" + String(mydht.temp_char_buffer);
  859.  
  860.     #if DEBUG
  861.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.temp_char_buffer : %s"), mydht.temp_char_buffer);
  862.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.buf_humidity     : %s"), mydht.buf_humidity);
  863.     #endif
  864.  
  865.     /*
  866.      *  konwersja float (humidity) do char[20] buffer
  867.      *  rzutowanie typów char[20] buffer do String -> mydht.buf_temperature
  868.      */
  869.      
  870.     snprintf(mydht.temp_char_buffer, sizeof mydht.temp_char_buffer, "%0.1fC", mydht.inside_devpoint);
  871.     mydht.buf_devpoint = "DevP:" + String(mydht.temp_char_buffer);
  872.  
  873.     #if DEBUG
  874.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.temp_char_buffer : %s"), mydht.temp_char_buffer);
  875.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> buf_devpoint           : %s"), mydht.buf_devpoint);
  876.     #endif
  877. }
  878.  
  879. /***************************************************************************************************************/
  880. /*    
  881.     @definition    statWiFi()
  882. */
  883. /***************************************************************************************************************/
  884.  
  885. void statWiFi()
  886. {
  887.     switch (WiFi.status())
  888.     {
  889.         case WL_NO_SSID_AVAIL:
  890.                               #if SERIAL
  891.                                   #if ENGLISH
  892.                                       Serial.printf_P ( PSTR ("\nConfigured SSID cannot be reached"));
  893.                                   #endif
  894.                                   #if POLISH
  895.                                       Serial.printf_P ( PSTR ("\nNie można osiągnąć skonfigurowanego identyfikatora SSID"));
  896.                                   #endif
  897.                                   #if GERMANY
  898.                                       Serial.printf_P ( PSTR ("\nKonfigurierte SSID ist nicht erreichbar"));
  899.                                   #endif
  900.                               #endif        
  901.                               break;
  902.                              
  903.         case WL_CONNECTED:
  904.                               #if SERIAL
  905.                                   #if ENGLISH
  906.                                       Serial.printf_P ( PSTR ("\nConnection successfully established"));
  907.                                       Serial.printf_P ( PSTR ("\nYour IP : %s"), WiFi.localIP().toString().c_str());
  908.                                       Serial.printf_P ( PSTR ("\nReceived Signal Strength Indication : %d"), WiFi.RSSI());
  909.                                   #endif
  910.                                   #if POLISH
  911.                                       Serial.printf_P ( PSTR ("\nPomyślnie nawiązano połączenie"));
  912.                                       Serial.printf_P ( PSTR ("\nTwój adres IP : %s"), WiFi.localIP().toString().c_str());
  913.                                       Serial.printf_P ( PSTR ("\nWskazanie siły odbieranego sygnału : %d"), WiFi.RSSI());
  914.                                   #endif
  915.                                   #if GERMANY
  916.                                       Serial.printf_P( PSTR ("\nVerbindung erfolgreich hergestellt"));
  917.                                       Serial.printf_P( PSTR ("\nDeine IP-Adresse : %s"), WiFi.localIP().toString().c_str());
  918.                                       Serial.printf_P( PSTR ("\nAnzeige der empfangenen Signalstärke : %d"), WiFi.RSSI());                                
  919.                                   #endif
  920.                               #endif
  921.                               break;
  922.                              
  923.         case WL_CONNECT_FAILED:
  924.                               #if SERIAL
  925.                                   #if ENGLISH
  926.                                       Serial.printf_P( PSTR ("\nConnection failed"));
  927.                                   #endif
  928.                                   #if POLISH
  929.                                       Serial.printf_P( PSTR ("\nPołączenie nieudane"));
  930.                                   #endif
  931.                                   #if GERMANY
  932.                                       Serial.printf_P( PSTR ("\nVerbindung fehlgeschlagen"));
  933.                                   #endif
  934.                               #endif
  935.                               break;
  936.       }      
  937. }
  938.  
  939. /***************************************************************************************************************/
  940. /*    
  941.     @definition    initWiFi()
  942. */
  943. /***************************************************************************************************************/
  944.  
  945. void initWiFi()
  946. {
  947.     WiFi.mode(WIFI_STA);
  948.     WiFi.begin(ssid, password);
  949.  
  950.     #if SERIAL    
  951.         #if ENGLISH
  952.             Serial.printf_P( PSTR ("\nConnecting to WiFi .."));
  953.         #endif
  954.         #if POLISH
  955.             Serial.printf_P( PSTR ( "\nŁącze z siecią WiFi .."));
  956.         #endif
  957.         #if GERMANY
  958.             Serial.printf_P( PSTR ("\nNetzwerkverbindung mit WLAN .."));
  959.         #endif
  960.     #endif
  961.      
  962.     while (WiFi.status() != WL_CONNECTED)
  963.     {
  964.         Serial.printf_P( PSTR( "." ));
  965.         delay(200);
  966.     }
  967.  
  968.     statWiFi();
  969.          
  970.     WiFi.setAutoReconnect(true);
  971.     WiFi.persistent(true);
  972. }
  973.  
  974. /***************************************************************************************************************/
  975. /*    
  976.     @definition    reconectWifi()
  977. */
  978. /***************************************************************************************************************/
  979.  
  980. void reconectWifi()
  981. {
  982.     unsigned long currentMillis = millis();
  983.      
  984.     if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval))
  985.     {
  986.         #if SERIAL
  987.             #if ENGLISH
  988.                 Serial.printf_P( PSTR ( "\nReconnecting to WiFi..."));
  989.             #endif
  990.             #if POLISH
  991.                 Serial.printf_P( PSTR ( "\nPonowne łączenie z Wi-Fi..."));
  992.             #endif
  993.             #if GERMANY
  994.                 Serial.printf_P( PSTR ( "\nErneut mit WLAN verbinden..."));
  995.             #endif
  996.         #endif
  997.          
  998.         WiFi.disconnect();
  999.         WiFi.begin(ssid, password);
  1000.          
  1001.         statWiFi();
  1002.          
  1003.         previousMillis = currentMillis;
  1004.     }
  1005. }
  1006.  
  1007. /***************************************************************************************************************/
  1008. /*    
  1009.     @definition    SerialTypeWriter
  1010. */
  1011. /***************************************************************************************************************/
  1012.  
  1013. void SerialTypeWriter(const String & message, unsigned int wait)
  1014. {
  1015.     for(const char c : message)
  1016.     {
  1017.         Serial.print(c);    
  1018.         delay(wait);  
  1019.     }
  1020. }
  1021.  
  1022. /***************************************************************************************************************/
  1023. /*    
  1024.     @definition    MorphingClock
  1025. */
  1026. /***************************************************************************************************************/
  1027.  
  1028. void MorphingClock()
  1029. {
  1030.     unsigned long epoch = timeClient.getEpochTime();  
  1031.  
  1032.     static int color_int = 1;
  1033.  
  1034.     if (epoch != prevEpoch)
  1035.     {
  1036.         int hh = timeClient.getHours();
  1037.         int mm = timeClient.getMinutes();
  1038.         int ss = timeClient.getSeconds();      
  1039.    
  1040.         if (prevEpoch == 0)
  1041.         {
  1042.             digit0.Draw(ss % 10);
  1043.             digit1.Draw(ss / 10);
  1044.             digit2.Draw(mm % 10);
  1045.             digit3.Draw(mm / 10);
  1046.             digit4.Draw(hh % 10);
  1047.             digit5.Draw(hh / 10);
  1048.            
  1049.             display.setTextColor(myCYAN);
  1050.             display.setCursor(2,0);
  1051.             display.print(MyClock.formated_date.c_str());
  1052.             display.setCursor(2,25);
  1053.             display.print(mydht.buf_temperature.c_str());
  1054.          }
  1055.          else
  1056.          {      
  1057.             if (ss!=prevss)
  1058.             {
  1059.                 int s0 = ss % 10;
  1060.                 int s1 = ss / 10;
  1061.                 if (s0!=digit0.Value()) digit0.Morph(s0);
  1062.                 if (s1!=digit1.Value()) digit1.Morph(s1);        
  1063.                 prevss = ss;
  1064.  
  1065.                 uint16_t myB;
  1066.                
  1067.                 if    (color_int)
  1068.                 {
  1069.                     color_int=0;
  1070.                     myB = myBlue0;
  1071.                 }
  1072.                 else              
  1073.                 {
  1074.                     color_int=1;
  1075.                     myB = myBLACK;
  1076.                 }
  1077.  
  1078.                 display.drawPixel(20,13,myB);
  1079.                 display.drawPixel(21,13,myB);
  1080.                 display.drawPixel(20,14,myB);
  1081.                 display.drawPixel(21,14,myB);
  1082.                 display.drawPixel(20,18,myB);
  1083.                 display.drawPixel(21,18,myB);
  1084.                 display.drawPixel(20,19,myB);
  1085.                 display.drawPixel(21,19,myB);
  1086.  
  1087.                 display.drawPixel(41,13,myB);
  1088.                 display.drawPixel(42,13,myB);
  1089.                 display.drawPixel(41,14,myB);
  1090.                 display.drawPixel(42,14,myB);
  1091.                 display.drawPixel(41,18,myB);
  1092.                 display.drawPixel(42,18,myB);
  1093.                 display.drawPixel(41,19,myB);
  1094.                 display.drawPixel(42,19,myB);
  1095.             }
  1096.             if (mm!=prevmm)
  1097.             {
  1098.                 int m0 = mm % 10;
  1099.                 int m1 = mm / 10;
  1100.                 if (m0!=digit2.Value()) digit2.Morph(m0);
  1101.                 if (m1!=digit3.Value()) digit3.Morph(m1);
  1102.                 display.setTextColor(myCYAN);
  1103.                 display.setCursor(2,0);
  1104.                 display.print(MyClock.formated_date.c_str());
  1105.                 display.setCursor(2,25);
  1106.                 display.print(mydht.buf_temperature.c_str());
  1107.                 prevmm = mm;
  1108.              }
  1109.      
  1110.              if (hh!=prevhh)
  1111.              {
  1112.                 int h0 = hh % 10;
  1113.                 int h1 = hh / 10;
  1114.                 if (h0!=digit4.Value()) digit4.Morph(h0);
  1115.                 if (h1!=digit5.Value()) digit5.Morph(h1);
  1116.                 prevhh = hh;
  1117.              }
  1118.         }
  1119.         prevEpoch = epoch;
  1120.     }  
  1121. }
  1122.  
  1123. /***************************************************************************************************************/
  1124. /*    
  1125.     @definition    ShowInfo
  1126. */
  1127. /***************************************************************************************************************/
  1128.  
  1129. void ShowInfo()
  1130. {
  1131.     Serial.printf_P( PSTR ("\n+-------------------------------------------------------------+"));
  1132.     Serial.printf_P( PSTR ("\n|        Morphing Clock v1.6 beta by Tomasz Majcher           |" ));    
  1133.     Serial.printf_P( PSTR ("\n|        support : ESP8266 + PxMatrix + DHT11                 |" ));      
  1134.     Serial.printf_P( PSTR ("\n|                                                             |" ));      
  1135.     Serial.printf_P( PSTR ("\n|        e-mail: [email protected]                  |" ));      
  1136.     Serial.printf_P( PSTR ("\n+-------------------------------------------------------------+\n"));
  1137. }
  1138.  
  1139. /***************************************************************************************************************/
  1140. /*    
  1141.     @definition    setup
  1142. */
  1143. /***************************************************************************************************************/
  1144.  
  1145. void setup()
  1146. {
  1147.     delay(300);
  1148.     #if SERIAL      
  1149.         Serial.begin(SerialSpeed);
  1150.         ShowInfo();
  1151.     #endif  
  1152.  
  1153.     DHT11.attach(DHT_PIN);                                // DHT11 sensor start
  1154.    
  1155.     initWiFi();                                           // start Wi-Fi  
  1156.  
  1157.     timeClient.begin();    
  1158.     runner.init();                                        // inicjalizuj scheluder                                                                                    
  1159.     runner.addTask(task_0);                               // dodaj zadanie do scheluder
  1160.     task_0.enable();                                      // włącz zadanie do scheluder
  1161.     runner.addTask(task_1);                               // dodaj zadanie do scheluder
  1162.     task_1.enable();                                      // włącz zadanie do scheluder
  1163.     runner.addTask(task_2);                               // dodaj zadanie do scheluder
  1164.     task_2.enable();                                      //  włącz zadanie do scheluder
  1165.     runner.addTask(task_3);                               // dodaj zadanie do scheluder
  1166.     task_3.enable();                                      // włącz zadanie do scheluder
  1167.     runner.addTask(task_4);                               // dodaj zadanie do scheluder
  1168.     task_4.enable();                                      // włącz zadanie do scheluder
  1169.      
  1170.      // --- WYWOŁAJ TERAZ --------------------- //
  1171.    
  1172.     Task1Callback();  
  1173.     Task2Callback();  
  1174.     Task3Callback();    
  1175.     Task4Callback();    
  1176.     Task4Callback();    
  1177.     Task4Callback();    
  1178.  
  1179.     display.begin(16);
  1180.     display_update_enable(true);
  1181.    
  1182.     display.fillScreen(display.color565(0, 0, 0));
  1183. }
  1184.  
  1185. /***************************************************************************************************************/
  1186. /*    
  1187.     @main    loop program
  1188. */
  1189. /***************************************************************************************************************/
  1190.  
  1191.  
  1192. void loop()
  1193. {
  1194.     runner.execute();     // scheluder init
  1195.     reconectWifi();       // check Wi-Fi status
  1196.     MorphingClock();
  1197.  
  1198. }
  1199.  
  1200. /***************************************************************************************************************/
  1201. /*    
  1202.     @definition    Digit Class
  1203. */
  1204. /***************************************************************************************************************/
  1205.  
  1206.  
  1207. Digit::Digit(PxMATRIX* d, byte value, uint16_t xo, uint16_t yo, uint16_t color)
  1208. {
  1209.     _display = d;
  1210.     _value = value;
  1211.     xOffset = xo;
  1212.     yOffset = yo;
  1213.     _color = color;
  1214. }
  1215.  
  1216. byte Digit::Value()
  1217. {
  1218.     return _value;
  1219. }
  1220.  
  1221. void Digit::drawPixel(uint16_t x, uint16_t y, uint16_t c)
  1222. {
  1223.     _display->drawPixel(xOffset + x, height - (y + yOffset), c);
  1224. }
  1225.  
  1226. void Digit::drawLine(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2, uint16_t c)
  1227. {
  1228.     _display->drawLine(xOffset + x, height - (y + yOffset), xOffset + x2, height - (y2 + yOffset), c);
  1229. }
  1230.  
  1231. void Digit::drawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t c)
  1232. {
  1233.     _display->fillRect(xOffset + x, height - (y + yOffset), w,h, c);
  1234. }
  1235.  
  1236. void Digit::DrawColon(uint16_t c)
  1237. {  
  1238.     drawFillRect(-3, segHeight-1, 2,2, c);
  1239.     drawFillRect(-3, segHeight+1+3, 2,2, c);
  1240. }
  1241.  
  1242. void Digit::drawSeg(byte seg)
  1243. {
  1244.     switch (seg)
  1245.     {
  1246.         case sA: drawLine(1, segHeight * 2 + 2, segWidth, segHeight * 2 + 2, _color); break;
  1247.         case sB: drawLine(segWidth + 1, segHeight * 2 + 1, segWidth + 1, segHeight + 2, _color); break;
  1248.         case sC: drawLine(segWidth + 1, 1, segWidth + 1, segHeight, _color); break;
  1249.         case sD: drawLine(1, 0, segWidth, 0, _color); break;
  1250.         case sE: drawLine(0, 1, 0, segHeight, _color); break;
  1251.         case sF: drawLine(0, segHeight * 2 + 1, 0, segHeight + 2, _color); break;
  1252.         case sG: drawLine(1, segHeight + 1, segWidth, segHeight + 1, _color); break;
  1253.     }
  1254. }
  1255.  
  1256. void Digit::Draw(byte value)
  1257. {
  1258.     byte pattern = digitBits[value];
  1259.     if (bitRead(pattern, 7)) drawSeg(sA);
  1260.     if (bitRead(pattern, 6)) drawSeg(sB);
  1261.     if (bitRead(pattern, 5)) drawSeg(sC);
  1262.     if (bitRead(pattern, 4)) drawSeg(sD);
  1263.     if (bitRead(pattern, 3)) drawSeg(sE);
  1264.     if (bitRead(pattern, 2)) drawSeg(sF);
  1265.     if (bitRead(pattern, 1)) drawSeg(sG);
  1266.     _value = value;
  1267. }
  1268.  
  1269. void Digit::Morph2()
  1270. {
  1271.     for (int i = 0; i <= segWidth; i++)
  1272.     {
  1273.         if (i < segWidth)
  1274.         {
  1275.             drawPixel(segWidth - i, segHeight * 2 + 2, _color);
  1276.             drawPixel(segWidth - i, segHeight + 1, _color);
  1277.             drawPixel(segWidth - i, 0, _color);
  1278.         }
  1279.  
  1280.         drawLine(segWidth + 1 - i, 1, segWidth + 1 - i, segHeight, black);
  1281.         drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1282.         delay(animSpeed);
  1283.     }
  1284. }
  1285.  
  1286. void Digit::Morph3()
  1287. {
  1288.     for (int i = 0; i <= segWidth; i++)
  1289.     {
  1290.         drawLine(0 + i, 1, 0 + i, segHeight, black);
  1291.         drawLine(1 + i, 1, 1 + i, segHeight, _color);
  1292.         delay(animSpeed);
  1293.     }
  1294. }
  1295.  
  1296. void Digit::Morph4()
  1297. {
  1298.     for (int i = 0; i < segWidth; i++)
  1299.     {
  1300.         drawPixel(segWidth - i, segHeight * 2 + 2, black); // Erase A
  1301.         drawPixel(0, segHeight * 2 + 1 - i, _color); // Draw as F
  1302.         drawPixel(1 + i, 0, black); // Erase D
  1303.         delay(animSpeed);
  1304.     }
  1305. }
  1306.  
  1307. void Digit::Morph5()
  1308. {
  1309.     for (int i = 0; i < segWidth; i++)
  1310.     {
  1311.         drawPixel(segWidth + 1, segHeight + 2 + i, black); // Erase B
  1312.         drawPixel(segWidth - i, segHeight * 2 + 2, _color); // Draw as A
  1313.         drawPixel(segWidth - i, 0, _color); // Draw D
  1314.         delay(animSpeed);
  1315.     }
  1316. }
  1317.  
  1318. void Digit::Morph6()
  1319. {
  1320.     for (int i = 0; i <= segWidth; i++)
  1321.     {
  1322.         drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1323.         if (i > 0) drawLine(segWidth - i + 1, 1, segWidth - i + 1, segHeight, black);
  1324.         delay(animSpeed);
  1325.     }
  1326. }
  1327.  
  1328. void Digit::Morph7()
  1329. {
  1330.     for (int i = 0; i <= (segWidth + 1); i++)
  1331.     {
  1332.         drawLine(0 + i - 1, 1, 0 + i - 1, segHeight, black);
  1333.         drawLine(0 + i, 1, 0 + i, segHeight, _color);
  1334.         drawLine(0 + i - 1, segHeight * 2 + 1, 0 + i - 1, segHeight + 2, black);
  1335.         drawLine(0 + i, segHeight * 2 + 1, 0 + i, segHeight + 2, _color);
  1336.         drawPixel(1 + i, 0, black); // D
  1337.         drawPixel(1 + i, segHeight + 1, black); // G
  1338.         delay(animSpeed);
  1339.     }
  1340. }
  1341.  
  1342. void Digit::Morph8()
  1343. {
  1344.     for (int i = 0; i <= segWidth; i++)
  1345.     {
  1346.         drawLine(segWidth - i, segHeight * 2 + 1, segWidth - i, segHeight + 2, _color);
  1347.         if (i > 0) drawLine(segWidth - i + 1, segHeight * 2 + 1, segWidth - i + 1, segHeight + 2, black);
  1348.  
  1349.         drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1350.         if (i > 0) drawLine(segWidth - i + 1, 1, segWidth - i + 1, segHeight, black);
  1351.  
  1352.         if (i < segWidth)
  1353.         {
  1354.             drawPixel(segWidth - i, 0, _color); // D
  1355.             drawPixel(segWidth - i, segHeight + 1, _color); // G
  1356.         }
  1357.         delay(animSpeed);
  1358.     }
  1359. }
  1360.  
  1361. void Digit::Morph9()
  1362. {
  1363.     for (int i = 0; i <= (segWidth + 1); i++)
  1364.     {
  1365.         drawLine(0 + i - 1, 1, 0 + i - 1, segHeight, black);
  1366.         drawLine(0 + i, 1, 0 + i, segHeight, _color);
  1367.         delay(animSpeed);
  1368.     }
  1369. }
  1370.  
  1371. void Digit::Morph0()
  1372. {
  1373.     for (int i = 0; i <= segWidth; i++)
  1374.     {
  1375.         if (_value==1)
  1376.         {
  1377.             drawLine(segWidth - i, segHeight * 2+1 , segWidth - i, segHeight + 2, _color);
  1378.             if (i > 0) drawLine(segWidth - i + 1, segHeight * 2+1, segWidth - i + 1, segHeight + 2, black);
  1379.             drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1380.             if (i > 0) drawLine(segWidth - i + 1, 1, segWidth - i + 1, segHeight, black);
  1381.             if (i<segWidth) drawPixel(segWidth - i, segHeight * 2 + 2 , _color); // Draw A
  1382.             if (i<segWidth) drawPixel(segWidth - i, 0, _color); // Draw D
  1383.         }
  1384.    
  1385.         if (_value==2)
  1386.         {
  1387.             drawLine(segWidth - i, segHeight * 2+1 , segWidth - i, segHeight + 2, _color);
  1388.             if (i > 0) drawLine(segWidth - i + 1, segHeight * 2+1, segWidth - i + 1, segHeight + 2, black);
  1389.             drawPixel(1+i, segHeight + 1, black); // Erase G left to right
  1390.             if (i<segWidth) drawPixel(segWidth + 1, segHeight + 1- i, _color);// Draw C
  1391.         }
  1392.  
  1393.         if (_value==3)
  1394.         {
  1395.             drawLine(segWidth - i, segHeight * 2+1 , segWidth - i, segHeight + 2, _color);
  1396.             if (i > 0) drawLine(segWidth - i + 1, segHeight * 2+1, segWidth - i + 1, segHeight + 2, black);
  1397.             drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1398.             if (i > 0) drawLine(segWidth - i + 1, 1, segWidth - i + 1, segHeight, black);
  1399.             drawPixel(segWidth - i, segHeight + 1, black); // G
  1400.          }
  1401.    
  1402.         if (_value==5)
  1403.         {
  1404.             if (i<segWidth)
  1405.             {
  1406.                 if (i>0) drawLine(1 + i, segHeight * 2 + 1, 1 + i, segHeight + 2, black);
  1407.                 drawLine(2 + i, segHeight * 2 + 1, 2 + i, segHeight + 2, _color);
  1408.             }
  1409.         }
  1410.    
  1411.         if (_value==5 || _value==9)
  1412.         {
  1413.               if (i<segWidth) drawPixel(segWidth - i, segHeight + 1, black);
  1414.               if (i<segWidth) drawPixel(0, segHeight - i, _color);
  1415.         }
  1416.         delay(animSpeed);
  1417.     }
  1418. }
  1419.  
  1420. void Digit::Morph1()
  1421. {
  1422.     for (int i = 0; i <= (segWidth + 1); i++)
  1423.     {
  1424.         drawLine(0 + i - 1, 1, 0 + i - 1, segHeight, black);
  1425.         drawLine(0 + i, 1, 0 + i, segHeight, _color);
  1426.         drawLine(0 + i - 1, segHeight * 2 + 1, 0 + i - 1, segHeight + 2, black);
  1427.         drawLine(0 + i, segHeight * 2 + 1, 0 + i, segHeight + 2, _color);
  1428.         drawPixel(1 + i, segHeight * 2 + 2, black); // A
  1429.         drawPixel(1 + i, 0, black); // D
  1430.         drawPixel(1 + i, segHeight + 1, black); // G
  1431.         delay(animSpeed);
  1432.     }
  1433. }
  1434.  
  1435. void Digit::Morph(byte newValue)
  1436. {
  1437.     switch (newValue)
  1438.     {
  1439.         case 2: Morph2(); break;
  1440.         case 3: Morph3(); break;
  1441.         case 4: Morph4(); break;
  1442.         case 5: Morph5(); break;
  1443.         case 6: Morph6(); break;
  1444.         case 7: Morph7(); break;
  1445.         case 8: Morph8(); break;
  1446.         case 9: Morph9(); break;
  1447.         case 0: Morph0(); break;
  1448.         case 1: Morph1(); break;
  1449.     }
  1450.     _value = newValue;
  1451. }
Advertisement
Add Comment
Please, Sign In to add comment