PowerTGS440

MorphingClock v3.0 Final

Apr 1st, 2022
1,007
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 91.51 KB | None | 0 0
  1. /*
  2.  * Morphing Clock by Tomasz Majcher (Transline Group)
  3.  * version      : 3.0 Final
  4.  * date         : 01.04.2022
  5.  * e-mail       : [email protected]
  6.  * mobile       : +48 667082121
  7.  */
  8.  
  9. extern "C" char* sbrk(int incr);
  10.  
  11. const char * version = "3.0 ";
  12.  
  13. /*
  14.  * History
  15.  *
  16.  * version 3.0      : final
  17.  *  
  18.  * version 2.9      : test
  19.  *
  20.  * version 2.8      : optymalization
  21.  *
  22.  * version 2.7      : test
  23.  *
  24.  * version 2.6      : build -> add clous (zachmurzenie), add pressure (ciśnienie atmosferyczne)
  25.  *
  26.  * version 2.5      : build -> add humidity (in/out), add day of week, modyfi multi-switch
  27.  *
  28.  * version 2.4      : build -> add outside temperature on PxMatrix
  29.  *
  30.  * version 2.3      : build -> add Hello Tomek msg on PxMatrix (debug on Serial Monitor)
  31.  *
  32.  * version 2.2      : modify -> memory optymalization -> before -> use 334237kB (32% progmem) / use 32240kB RAM free 49680kB RAM
  33.  *                                                    -> now    -> use 334285kB (32% progmem) / use 31028kB RAM free 50892kB RAM
  34.  *
  35.  * version 2.1      : build -> JSON parse value from open.weather.com & display (SERIAL DEBUG ONLY)
  36.  *
  37.  * version 2.0      : build -> get value from open.weather.com
  38.  *
  39.  * version 1.9      : modify -> summer time
  40.  *
  41.  * version 1.8      : build -> multi-display (humidity / date)
  42.  *
  43.  * version 1.7      : repair -> clean old temperature on screen & display new temperature
  44.  *
  45.  * version 1.6      : modify -> refresh (interal 1 minute) display temp (before interval 1 hours)
  46.  *
  47.  * version 1.5      : modify -> speeding up the speed of the morphing animation
  48.  *
  49.  * version 1.4      : modify -> memory optymalization -> before -> use 307593kB (29% progmem) / use 29884kB RAM free 52036 kB RAM
  50.  *                                                    -> now    -> use 307585kB (29% progmem) / use 29876kB RAM free 52044 kB RAM (save : 216bytes RAM, 856bytes PROGMEM) to version 1.1
  51.  *                                                    
  52.  * version 1.3      : modify -> memory optymalization -> before -> use 307609kB (29% progmem) / use 29908kB RAM free 52021 kB RAM
  53.  *                                                    -> now    -> use 307593kB (29% progmem) / use 29884kB RAM free 52036 kB RAM
  54.  *                                                    
  55.  * version 1.2      : modify -> memory optymalization -> before -> use 308441kB (29% progmem) / use 30092kB RAM free 51925 kB RAM
  56.  *                                                    -> now    -> use 307609kB (29% progmem) / use 29908kB RAM free 52012 kB RAM
  57.  *                                                    
  58.  * version 1.1      : repair -> debug & find & bug
  59.  * version 1.0      : test
  60.  * version 0.9      : build -> add DHT11 sensor and tested : build buffor for humidity & devPoint
  61.  * version 0.8      : build -> add DHT11 sensor and tested : show temperature on PxMatrix
  62.  * version 0.7      : test
  63.  * version 0.6      : build
  64.  * version 0.5      : build
  65.  * version 0.4      : build
  66.  * version 0.3      : build
  67.  */
  68.  
  69. #define ARRAY_SIZE(a)   (sizeof(a) / sizeof((a)[0]))
  70.  
  71. #define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
  72. #define F(string_literal) (FPSTR(PSTR(string_literal)))
  73.  
  74. /***************************************************************************************************************/
  75. /*!
  76.     @define   macro
  77.     @create   macro-time
  78. */
  79. /***************************************************************************************************************/
  80.  
  81. #define TIME_01S      1000                                     // 1 sekunda
  82. #define TIME_10S     10000                                     // 10 sekund
  83. #define TIME_01M     60000                                     // 1 minuta
  84. #define TIME_05M    360000                                     // 5 minut
  85. #define TIME_10M    600000                                     // 10 minut
  86. #define TINE_01H   3600000                                     // 1 godzina
  87.  
  88. /***************************************************************************************************************/
  89. /*!
  90.     @library  PxMatrix.h
  91.     @include  library, font
  92.     @define   pin, width, height
  93.     @create   object PxMatrix
  94. */
  95. /***************************************************************************************************************/
  96.  
  97. #include <PxMatrix.h>                                       // załączenie biblioteki
  98.  
  99. #define P_LAT 16                                            // definicja pin : P_LAT
  100. #define P_A 5                                               // definicja pin : P_A
  101. #define P_B 4                                               // definicja pin : P_B
  102. #define P_C 15                                              // definicja pin : P_C
  103. #define P_D 12                                              // definicja pin : P_D
  104. #define P_E 0                                               // definicja pin : P_E
  105. #define P_OE 2                                              // definicja pin : P_OE
  106.  
  107. #define matrix_width 64                                     // definicja  : szerokość wyświetlacza
  108. #define matrix_height 32                                    // definicja  : wysokość wyświetlacza
  109.  
  110. const uint8_t display_draw_time=10;                         // zmienna : display_draw_time
  111. const byte animSpeed = 15;                                  // zmienna : prędkość animacji (morphing digit)
  112.  
  113. PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);        // utwórz obiekt display klasy PxMatrix
  114.  
  115. /***************************************************************************************************************/
  116. /*!
  117.     @library  Ticker.h
  118.     @include  library
  119.     @define   function
  120. */
  121. /***************************************************************************************************************/
  122.  
  123. #include <Ticker.h>
  124.  
  125. Ticker display_ticker;
  126.  
  127. void display_updater();                                     // definicja funkcji
  128. void display_update_enable(bool is_enable);                 // definicja funkcji
  129.  
  130. /***************************************************************************************************************/
  131. /*!
  132.     @value    Digit    
  133.     @class    Digit
  134. */
  135. /***************************************************************************************************************/
  136.  
  137. const byte sA = 0;
  138. const byte sB = 1;
  139. const byte sC = 2;
  140. const byte sD = 3;
  141. const byte sE = 4;
  142. const byte sF = 5;
  143. const byte sG = 6;
  144. const int segHeight = 6;
  145. const int segWidth = segHeight;
  146. const uint16_t height = 31;
  147. const uint16_t width = 63;
  148.  
  149. const byte digitBits[] =
  150. {
  151.     B11111100, // 0 ABCDEF--
  152.     B01100000, // 1 -BC-----
  153.     B11011010, // 2 AB-DE-G-
  154.     B11110010, // 3 ABCD--G-
  155.     B01100110, // 4 -BC--FG-
  156.     B10110110, // 5 A-CD-FG-
  157.     B10111110, // 6 A-CDEFG-
  158.     B11100000, // 7 ABC-----
  159.     B11111110, // 8 ABCDEFG-
  160.     B11110110, // 9 ABCD_FG-
  161. };
  162.  
  163. uint16_t black;
  164.  
  165. /***************************************************************************************************************/
  166. /*!
  167.     @class    Digit    
  168. */
  169. /***************************************************************************************************************/
  170.  
  171. class Digit
  172. {
  173.     public:
  174.         Digit(PxMATRIX* d, byte value, uint16_t xo, uint16_t yo, uint16_t color);
  175.         void Draw(byte value);
  176.         void Morph(byte newValue);
  177.         byte Value();
  178.         void DrawColon(uint16_t c);
  179.    
  180.     private:
  181.         PxMATRIX* _display;
  182.         byte _value;
  183.         uint16_t _color;
  184.         uint16_t xOffset;
  185.         uint16_t yOffset;        
  186.  
  187.         void drawPixel(uint16_t x, uint16_t y, uint16_t c);
  188.         void drawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t c);
  189.         void drawLine(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2, uint16_t c);
  190.         void drawSeg(byte seg);
  191.         void Morph2();
  192.         void Morph3();
  193.         void Morph4();
  194.         void Morph5();
  195.         void Morph6();
  196.         void Morph7();
  197.         void Morph8();
  198.         void Morph9();
  199.         void Morph0();
  200.         void Morph1();
  201. };
  202.  
  203. /***************************************************************************************************************/
  204. /*!
  205.     @library  Digit.h
  206.     @include  library
  207.     @define  
  208.     @create   object
  209. */
  210. /***************************************************************************************************************/
  211.  
  212. Digit digit0(&display, 0, 63 - 1 - 9*1, 9, display.color565(0, 0, 155));
  213. Digit digit1(&display, 0, 63 - 1 - 9*2, 9, display.color565(0, 0, 155));
  214. Digit digit2(&display, 0, 63 - 4 - 9*3, 9, display.color565(0, 0, 155));
  215. Digit digit3(&display, 0, 63 - 4 - 9*4, 9, display.color565(0, 0, 155));
  216. Digit digit4(&display, 0, 63 - 7 - 9*5, 9, display.color565(0, 0, 155));
  217. Digit digit5(&display, 0, 63 - 7 - 9*6, 9, display.color565(0, 0, 155));
  218.  
  219. /***************************************************************************************************************/
  220. /*!
  221.     @library  ESP8266WiFi.h
  222.     @include  library
  223.     @define   ssid, password
  224.     @create   object
  225. */
  226. /***************************************************************************************************************/
  227.  
  228. #include <ESP8266WiFi.h>                                          // biblioteka do obsługi wi-fi
  229.  
  230. const char *ssid     = "DIABLO";                                  // network wifi ssid  
  231. const char *password = "xxxxxxxxxxxx";                             // network wifi password
  232.  
  233. unsigned long previousMillis = 0;                                 // re-conect Wi-FI
  234. const unsigned long interval = 30000;                             // re-conect Wi-FI
  235.  
  236. /***************************************************************************************************************/
  237. /*!
  238.     @library  <ESP8266HTTPClient.h> <WiFiClient.h> <Arduino_JSON.h>
  239.     @include  library
  240.     @define   ssid, password
  241.     @create   object
  242. */
  243. /***************************************************************************************************************/
  244.  
  245. #include <ESP8266HTTPClient.h>
  246. #include <WiFiClient.h>
  247. #include <Arduino_JSON.h>
  248.  
  249. String WeatherToken  = "xxxxxTwójxxApixxxxxxxxxxxxxxxxx";                    // token serwera pogodowego http://api.weatherapi.com
  250. String WeatherCity   = "Lubin";                                              // miasto dla ścieżki HTTP  http://api.weatherapi.com
  251.  
  252. String WeatherServer = "http://api.weatherapi.com/v1/current.json?key=" + WeatherToken + "&q=" + WeatherCity + "&lang=pl";
  253.  
  254. bool WeatherUpdate = false;                                                  // flaga : aktualizacja pogody
  255.                                                                              // jeśli ma wartość : false -> brak aktualizacji
  256.                                                                              // jeśli ma wartość : true  -> zaktualizowano
  257.                                                                              // aktualizacja odbywa się w task_0 wg. interwału
  258.  
  259. #define DEBUG_WEATHER 0                                                      // jeśli DEBUG_WEATHER 1 pokaż dane ze struktuty na Serial Monitor
  260.                                                                              // jeśli DEBUG_WEATHER 0 nie pokaazuj danych na Serial Monitor
  261.  
  262. /***************************************************************************************************************/
  263. /*!
  264.     @library      TaskScheduler.h
  265.     @include      library
  266.     @declaration  function
  267.     @create       object
  268. */
  269. /***************************************************************************************************************/
  270.  
  271. #include <TaskScheduler.h>                                                // scheluder
  272.  
  273. void Task0Callback();                                                     // funkcja dla task_0    
  274. void Task1Callback();                                                     // funkcja dla task_1    
  275. void Task2Callback();                                                     // funkcja dla task_2    
  276. void Task3Callback();                                                     // funkcja dla task_3    
  277. void Task4Callback();                                                     // funkcja dla task_4    
  278.  
  279. Task task_0(  TIME_05M,  TASK_FOREVER, &Task0Callback);                   // task_0 - co 5 minutę
  280. Task task_1(  TIME_01M,  TASK_FOREVER, &Task1Callback);                   // task_1 - co 1 sekundę  
  281. Task task_2(  TIME_01S,  TASK_FOREVER, &Task2Callback);                   // task_2 - co 1 sekundę  
  282. Task task_3(  TIME_10M,  TASK_FOREVER, &Task3Callback);                   // task_3 - co 1 sekundę
  283. Task task_4(  TIME_05M,  TASK_FOREVER, &Task4Callback);                   // task_4 - co 5 minut                                                                                                      
  284.  
  285. Scheduler runner;      
  286.  
  287. /***************************************************************************************************************/
  288. /*!
  289.     @library      TimeLib.h, WifiUdp.h, NTPClient_Generic.h
  290.     @include      library
  291.     @declaration  timefunction
  292.     @create       object
  293. */
  294. /***************************************************************************************************************/
  295.  
  296. #include <NTPClient_Generic.h>                                    // NTP klient (Time)
  297. #include <WiFiUdp.h>                                              // UDP dla NTP (Time)
  298. #include <TimeLib.h>                                              // TimeLib
  299.  
  300. WiFiUDP ntpUDP;  
  301.  
  302. const char timeServer[] = "0.pl.pool.ntp.org";
  303.    
  304. #define TIME_ZONE_OFFSET_HRS            2                        // Europe, Poland (2)
  305. #define NTP_UPDATE_INTERVAL_MS          60000L                   // update interval
  306.  
  307. NTPClient timeClient(ntpUDP, timeServer, (3600 * TIME_ZONE_OFFSET_HRS), NTP_UPDATE_INTERVAL_MS);                                    
  308.  
  309. bool F_TimeUpdate = false;                                       // flag to update (second)
  310. unsigned long prevEpoch;
  311. byte prevhh;
  312. byte prevmm;
  313. byte prevss;
  314.  
  315. /***************************************************************************************************************/
  316. /*!
  317.     @library      dht11.h
  318.     @include      library
  319.     @declaration  temperature, humidity
  320.     @create       object
  321. */
  322. /***************************************************************************************************************/
  323.  
  324. #include <dht11.h>
  325. #define DHT_PIN 0
  326.  
  327. dht11 DHT11;
  328.  
  329.  
  330. /***************************************************************************************************************/
  331. /*
  332.     @declaration   function
  333. */
  334. /***************************************************************************************************************/
  335.  
  336. void statWiFi();
  337. void initWiFi();
  338. void reconectWifi();
  339. void SerialTypeWriter(const String & message, unsigned int wait);
  340. void ShowInfo();                                                        // pokaż INTRO
  341. String httpGETRequest(const char* serverName);                          // pobierz dane z www
  342. void DisplayStart();                                                    // init PxMatrix
  343. void DisplayReset();                                                    // reset PxMatrix (black & set font size 1)
  344. void MatrixTypeWriter(const String & message, unsigned int wait);       // type writer dla PxMatrix
  345.  
  346.  
  347. /***************************************************************************************************************/
  348. /*!
  349.     @colour   standard    
  350. */
  351. /***************************************************************************************************************/
  352.  
  353. const uint16_t myRED = display.color565(255, 0, 0);
  354. const uint16_t myGREEN = display.color565(0, 100, 0);
  355. const uint16_t myGREEN2 = display.color565(0, 70, 0);
  356. const uint16_t myBLUE = display.color565(0, 0, 255);
  357. const uint16_t myWHITE = display.color565(255, 255, 255);
  358. const uint16_t myYELLOW = display.color565(255, 255, 0);
  359. const uint16_t myCYAN = display.color565(0, 255, 255);
  360. const uint16_t myMAGENTA = display.color565(255, 0, 255);
  361. const uint16_t myBLACK = display.color565(0, 0, 0);
  362. const uint16_t mySha = display.color565(54,47,36);
  363. const uint16_t myROSE = display.color565(255,0,127);
  364.  
  365. const uint16_t myCOLORS[8]  = {myRED,myGREEN,myBLUE,myWHITE,myYELLOW,myCYAN,myMAGENTA,myBLACK};
  366. const uint16_t myCOLORS2[9] = {myRED, myGREEN, myWHITE, myMAGENTA, myBLUE, myYELLOW, myCYAN, mySha, myROSE};
  367.  
  368. /***************************************************************************************************************/
  369. /*!
  370.     @colour   Blue    
  371. */
  372. /***************************************************************************************************************/
  373.  
  374. const uint16_t myBlue0 = display.color565(0,   0, 255);
  375. const uint16_t myBlue1 = display.color565(0,  30, 255);
  376. const uint16_t myBlue2 = display.color565(0,  60, 255);
  377. const uint16_t myBlue3 = display.color565(0,  90, 255);
  378. const uint16_t myBlue4 = display.color565(0, 120, 255);
  379. const uint16_t myBlue5 = display.color565(0, 150, 255);
  380. const uint16_t myBlue6 = display.color565(0, 180, 255);
  381. const uint16_t myBlue7 = display.color565(0, 210, 255);
  382. const uint16_t myBlue8 = display.color565(0, 250, 255);
  383.  
  384. const uint16_t myBlue[9] = {myBlue0, myBlue1, myBlue2, myBlue3, myBlue4, myBlue5, myBlue6, myBlue7, myBlue8};
  385.  
  386. /***************************************************************************************************************/
  387. /*!
  388.     @colour   Dark
  389. */    
  390. /***************************************************************************************************************/
  391.  
  392. const uint16_t myDark0 = display.color565(20, 20, 20);
  393. const uint16_t myDark1 = display.color565(25, 25, 25);
  394. const uint16_t myDark2 = display.color565(30, 30, 30);
  395. const uint16_t myDark3 = display.color565(35, 35, 35);
  396. const uint16_t myDark4 = display.color565(40, 40, 40);
  397. const uint16_t myDark5 = display.color565(45, 45, 45);
  398. const uint16_t myDark6 = display.color565(50, 50, 50);
  399. const uint16_t myDark7 = display.color565(55, 55, 55);
  400. const uint16_t myDark8 = display.color565(60, 60, 60);
  401.  
  402. const uint16_t myDark[9] = {myDark0, myDark1, myDark2, myDark3, myDark4, myDark5, myDark6, myDark7, myDark8};
  403.  
  404. /***************************************************************************************************************/
  405. /*!
  406.     @colour   DarkRed
  407. */
  408. /***************************************************************************************************************/
  409.  
  410. const uint16_t myDarkRed0 = display.color565(20, 1,   8);
  411. const uint16_t myDarkRed1 = display.color565(31, 1,  12);
  412. const uint16_t myDarkRed2 = display.color565(36, 1,  14);
  413. const uint16_t myDarkRed3 = display.color565(41, 1,  16);
  414. const uint16_t myDarkRed4 = display.color565(46, 1,  18);
  415. const uint16_t myDarkRed5 = display.color565(50, 1,  20);
  416. const uint16_t myDarkRed6 = display.color565(54, 1,  24);
  417. const uint16_t myDarkRed7 = display.color565(58, 1,  28);
  418. const uint16_t myDarkRed8 = display.color565(64, 1,  32);
  419.  
  420. const uint16_t myDarkRed[9] = {myDarkRed0, myDarkRed1, myDarkRed2, myDarkRed3, myDarkRed4, myDarkRed5, myDarkRed6, myDarkRed7, myDarkRed8};
  421.  
  422. /***************************************************************************************************************/
  423. /*!
  424.     @colour   DarkSea  
  425. */
  426. /***************************************************************************************************************/
  427. const uint16_t myDarkSea0 = display.color565(1, 10,  32);
  428. const uint16_t myDarkSea1 = display.color565(1, 14,  36);
  429. const uint16_t myDarkSea2 = display.color565(1, 16,  38);
  430. const uint16_t myDarkSea3 = display.color565(1, 20,  40);
  431. const uint16_t myDarkSea4 = display.color565(1, 24,  42);
  432. const uint16_t myDarkSea5 = display.color565(1, 28,  44);
  433. const uint16_t myDarkSea6 = display.color565(1, 32,  46);
  434. const uint16_t myDarkSea7 = display.color565(1, 36,  48);
  435. const uint16_t myDarkSea8 = display.color565(1, 40,  50);
  436.  
  437. const uint16_t myDarkSea[9] = {myDarkSea0, myDarkSea1, myDarkSea2, myDarkSea3, myDarkSea4, myDarkSea5, myDarkSea6, myDarkSea7, myDarkSea8};
  438.  
  439. /***************************************************************************************************************/
  440. /*!
  441.     @definition   Weekday, Month
  442. */
  443. /***************************************************************************************************************/
  444.  
  445. const char* Weekday[7] = {"Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"};
  446. const char* Months []= {"Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  447.  
  448. /***************************************************************************************************************/
  449. /*!
  450.     @define   Serial Setup & Language Setup
  451. */
  452. /***************************************************************************************************************/
  453.  
  454. #define LANGUAGE 0                                            // 0 (Polish), 1 (English), 2 (Germany)
  455.                                                                
  456. #if LANGUAGE == 0                                                
  457.     #define POLISH 1
  458.     #define ENGLISH 0
  459.     #define GERMANY 0                                          
  460. #endif
  461.    
  462. #if LANGUAGE == 1                                                      
  463.     #define POLISH 0                                        
  464.     #define ENGLISH 1
  465.     #define GERMANY 0
  466. #endif
  467.  
  468. #if LANGUAGE == 2
  469.     #define POLISH 0
  470.     #define ENGLISH 0
  471.     #define GERMANY 1
  472. #endif      
  473.  
  474. #define SERIAL true
  475. #define SerialSpeed 57600
  476.  
  477. #define DEBUG true
  478.  
  479. /***************************************************************************************************************/
  480. /*    
  481.     @declaration    function
  482.     @function       display_updater()
  483.     @function       display_update_enable(bool is_enable)
  484. */
  485. /***************************************************************************************************************/
  486.  
  487. void display_updater()
  488. {
  489.     display.display(display_draw_time);
  490. }
  491.  
  492. void display_update_enable(bool is_enable)
  493. {
  494.     if (is_enable)
  495.     {
  496.         display_ticker.attach(0.004, display_updater);
  497.     }
  498.     else
  499.     {
  500.         display_ticker.detach();
  501.     }
  502. }
  503.  
  504. /***************************************************************************************************************/
  505. /*    
  506.     @struct         TIME_DATA    
  507. */
  508. /***************************************************************************************************************/
  509.  
  510. struct TIME_DATA
  511. {
  512.       int Hour = 0;
  513.       int Minute  = 0;
  514.       int Second = 0;    
  515.       int DayOfTheWeek = 0;
  516.       int DayOfTheMonth = 0;
  517.       int Day = 0;
  518.       int Month = 0;
  519.       int Year = 0;
  520.       String formated_date = "";
  521. }
  522. MyClock;
  523.  
  524. /***************************************************************************************************************/
  525. /*    
  526.     @struct         HomeClimat  
  527. */
  528. /***************************************************************************************************************/
  529.  
  530. struct  HOME_CLIMAT
  531. {
  532.     float  inside_temperature  = 0;
  533.     float  prev_inside_temperature = 0;
  534.     int    inside_humidity     = 0;
  535.     int    prev_inside_humidity = 0;
  536.     float  inside_devpoint     = 0;    
  537.     char   temp_char_buffer[20];                        // bufor
  538.     String buf_temperature = "no data";                 // bufor
  539.     String buf_humidity    = "no data";                 // bufor
  540.     String buf_devpoint    = "no data";                 // bufor
  541. }
  542. mydht;
  543.  
  544. bool F_temp = false;      // flaga - jeśli zmieniła się temperatura TRUE
  545. bool F_humi = false;      // flaga - jeśli zmieniła się wilgotność to TRUE
  546.  
  547. /***************************************************************************************************************/
  548. /*    
  549.     @struct         OutsideClimat  
  550. */
  551. /***************************************************************************************************************/
  552.  
  553. struct  OUTSIDE_CLIMAT
  554. {
  555.     char      city[30];                 // ok - miasto
  556.     char      country[30];              // ok - kraj
  557.     char      tz_id[30];                // ok - kontynent/stolica
  558.     double    lat = 0;                  // ok - szerokość geograficzna
  559.     double    lon = 0;                  // ok - długość geograficzna
  560.     int       localtime_epoch = 0;      // ok - czas lokalny - format epoch (1629046610)
  561.     char      localtime[30];            // ok - czas lokalny - format string (2021-08-15 18:56)
  562.     char      last_updated[30];         // ok - czas ostatniej aktualizacji - format string (2021-08-15 18:45)
  563.     double    temp_c = 0;               // ok - temperatura w st.C
  564.     double    feelslike_c = 0;          // ok - temperatura odczuwalna w st.C
  565.     double    temp_f = 0;               // ok - temperatura w st.F
  566.     double    feelslike_f = 0;          // ok - temperatura odczuwalna w st.F
  567.     char      condition_en[50];         // ok - kondycja pogody np. Sunny, Cloud, etc
  568.     char      condition_pl[50];         // ok - kondycja pogody np. Słonecznie, Pochmurnie, etc
  569.     char      icon[100];                // ok - adres grafiki //cdn.weatherapi.com/weather/64x64/day/113.png
  570.     int       code = 0;                 // ok - kod czegoś, 1000
  571.     double    wind_mph = 0;             // ok - prędkość wiatru w milach/h
  572.     double    wind_kph = 0;             // ok - prędkość wiatru w km/h
  573.     int       wind_degree = 0;          // ok - kierunek wiatru w stopniach
  574.     char      wind_dir[10];             // ok - kierunek wiatru np. NNE
  575.     int       pressure_mb = 0;          // ok - cisnienie atmosferyczne
  576.     double    pressure_in = 0;          // ok - huj wie co to !!!
  577.     double    precip_mm = 0;            // ok - opady [mm]
  578.     double    precip_in = 0;            // ok - huj wie co to !!!
  579.     int       humidity = 0;             // ok - wilgotnosc powietrza
  580.     int       cloud = 0;                // zachmurzenie
  581.     double    vis_km = 0;               // widzialność w km
  582.     double    vis_miles = 0;            // widzialność w milach
  583.     double    uv = 0;                   // index UV
  584.     double    gust_mph = 0;             // * porywy wiatru w milach
  585.     double    gust_kph = 0;             // * porywy wiatru w kilometrach
  586.     char      char_buffer[20];          // bufor
  587.     String    temp_str_buffer = "no data";    // bufor
  588.     String    humi_str_buffer = "no data";    // bufor
  589.     char      pressure_buffer[12];            // bufor
  590.     char      cloud_buffer[12];               // bufor
  591. }
  592. weather;
  593.  
  594. /***************************************************************************************************************/
  595. /*    
  596.     @variable     string buffer to show on PxMatrix (up) msg_buffer_up
  597.                   string buffer to show on PxMatrix (down) msg_buffer_down
  598. */
  599. /***************************************************************************************************************/
  600.  
  601. String msg_buffer_up    = "HELLO TOMEK";
  602. String msg_buffer_down  = "PX MATRIX";
  603.  
  604. /***************************************************************************************************************/
  605. /*    
  606.     @declaration    DAY PL, EN, DE    
  607. */
  608. /***************************************************************************************************************/
  609.  
  610. #if POLISH
  611.       const char Day_0 [] = "Niedziela";
  612.       const char Day_1 [] = "Poniedzialek";
  613.       const char Day_2 [] = "Wtorek";
  614.       const char Day_3 [] = "Sroda";
  615.       const char Day_4 [] = "Czwartek";
  616.       const char Day_5 [] = "Piatek";
  617.       const char Day_6 [] = "Sobota";
  618. #endif
  619.  
  620. #if ENGLISH
  621.       const char Day_0 [] = "Sunday";
  622.       const char Day_1 [] = "Monday";
  623.       const char Day_2 [] = "Tuesday";
  624.       const char Day_3 [] = "Wednesday";
  625.       const char Day_4 [] = "Thursday";
  626.       const char Day_5 [] = "Friday";
  627.       const char Day_6 [] = "Saturday";
  628. #endif
  629.  
  630. #if GERMANY
  631.       const char Day_0 [] = "Sonntag";
  632.       const char Day_1 [] = "Montag";
  633.       const char Day_2 [] = "Dienstag";
  634.       const char Day_3 [] = "Mittwoch";
  635.       const char Day_4 [] = "Donnerstag";
  636.       const char Day_5 [] = "Freitag";
  637.       const char Day_6 [] = "Samstag";
  638. #endif
  639.  
  640. const char * const DAY[] = { Day_0, Day_1, Day_2, Day_3, Day_4, Day_5, Day_6 }; // dni tygodnia [0..6]
  641.  
  642. /***************************************************************************************************************/
  643. /*    
  644.     @declaration    MONTH PL, EN, DE    
  645. */
  646. /***************************************************************************************************************/
  647.  
  648. #if POLISH
  649.       const char MONTH_0  [] = "NULL";
  650.       const char MONTH_1  [] = "Styczen";
  651.       const char MONTH_2  [] = "Luty";
  652.       const char MONTH_3  [] = "Marzec";
  653.       const char MONTH_4  [] = "Kwiecien";
  654.       const char MONTH_5  [] = "Maj";
  655.       const char MONTH_6  [] = "Czerwiec";
  656.       const char MONTH_7  [] = "Lipiec";
  657.       const char MONTH_8  [] = "Sierpien";
  658.       const char MONTH_9  [] = "Wrzesien";
  659.       const char MONTH_10 [] = "Pazdziernik";
  660.       const char MONTH_11 [] = "Listopad";
  661.       const char MONTH_12 [] = "Grudzien";
  662. #endif
  663.  
  664. #if ENGLISH
  665.       const char MONTH_0  [] = "NULL";
  666.       const char MONTH_1  [] = "January";
  667.       const char MONTH_2  [] = "February";
  668.       const char MONTH_3  [] = "March";
  669.       const char MONTH_4  [] = "April";
  670.       const char MONTH_5  [] = "May";
  671.       const char MONTH_6  [] = "June";
  672.       const char MONTH_7  [] = "July";
  673.       const char MONTH_8  [] = "August";
  674.       const char MONTH_9  [] = "September";
  675.       const char MONTH_10 [] = "October";
  676.       const char MONTH_11 [] = "November";
  677.       const char MONTH_12 [] = "December";
  678. #endif
  679.  
  680. #if GERMANY
  681.       const char MONTH_0  [] = "NULL";
  682.       const char MONTH_1  [] = "Januar";
  683.       const char MONTH_2  [] = "Februar";
  684.       const char MONTH_3  [] = "März";
  685.       const char MONTH_4  [] = "April";
  686.       const char MONTH_5  [] = "Mai";
  687.       const char MONTH_6  [] = "Juni";
  688.       const char MONTH_7  [] = "Juli";
  689.       const char MONTH_8  [] = "August";
  690.       const char MONTH_9  [] = "September";
  691.       const char MONTH_10 [] = "Oktober";
  692.       const char MONTH_11 [] = "November";
  693.       const char MONTH_12 [] = "Dezember";
  694. #endif
  695.      
  696. const char * const MONTH[] = { MONTH_0, MONTH_1, MONTH_2, MONTH_3, MONTH_4, MONTH_5, MONTH_6,
  697.                                MONTH_7, MONTH_8, MONTH_9, MONTH_10, MONTH_11, MONTH_12 };
  698.  
  699.  
  700. /***************************************************************************************************************/
  701. /*    
  702.     @definition     Task0Callback
  703.     @interval       1 sekunda
  704.     @task           Get Weather from open.weather.com
  705. */
  706. /***************************************************************************************************************/
  707.  
  708. void Task0Callback()
  709. {
  710.     /********************************************
  711.     /* jeśli WiFi O.K.
  712.     /*******************************************/
  713.      
  714.     if(WiFi.status()== WL_CONNECTED)
  715.     {
  716.         JSONVar doc;
  717.         doc = JSON.parse(httpGETRequest(WeatherServer.c_str()));
  718.  
  719.         // --- update struct WEATHER ------------------------------------------------------ //
  720.        
  721.         strcpy(weather.city, doc["location"]["name"]);                       // nazwę miasta
  722.         strcpy(weather.country, doc["location"]["country"]);                 // nazwę kraju
  723.         weather.lat = double(doc["location"]["lat"]);                        // szer.geograficzną
  724.         weather.lon = double(doc["location"]["lon"]);                        // dł.geograficzną      
  725.         strcpy(weather.tz_id, doc["location"]["tz_id"]);                     // kontynent/stolica
  726.         weather.localtime_epoch = doc["location"]["localtime_epoch"];        // czas EPOCH
  727.         strcpy(weather.localtime, doc["location"]["localtime"]);             // czas lokalny
  728.         strcpy(weather.last_updated, doc["current"]["last_updated"]);        // ost. aktualizacja
  729.         weather.temp_c = double(doc["current"]["temp_c"]);                   // temp Celcius
  730.         weather.feelslike_c = double(doc["current"]["feelslike_c"]);         // temp odczuwalna C
  731.         weather.temp_f = double(doc["current"]["temp_f"]);                   // temp Faranhaid
  732.         weather.feelslike_f = double(doc["current"]["feelslike_f"]);         // temp odczuwalna Faranhaid
  733.         strcpy(weather.condition_en, doc["current"]["condition"]["text"]);   // opis pogody ENGLISH
  734.         strcpy(weather.condition_pl, doc["current"]["condition"]["text"]);   // opis pogody POLISH *** do zrobienia ***
  735.         strcpy(weather.icon, doc["current"]["condition"]["icon"]);           // adres ikony pogody
  736.         weather.code = doc["current"]["condition"]["code"];                  // kod pogody
  737.         weather.wind_kph = double(doc["current"]["wind_kph"]);               // prędkość wiatru w km/h
  738.         weather.gust_kph = double(doc["current"]["gust_kph"]);               // porywy wiatru w km/h
  739.         weather.wind_mph = double(doc["current"]["wind_mph"]);               // prędkość wiatru w milach/h
  740.         weather.gust_mph = double(doc["current"]["gust_mph"]);               // porywy wiatru w milach/h
  741.         weather.wind_degree = doc["current"]["wind_degree"];                 // kierunek wiatru (stopnie) int
  742.         strcpy(weather.wind_dir, doc["current"]["wind_dir"]);                // kierunke wiatru (dir)
  743.         weather.pressure_mb = doc["current"]["pressure_mb"];                 // cisnienie atmosferyczne
  744.         weather.pressure_in = double(doc["current"]["pressure_in"]);         // huj wie co to !!!
  745.         weather.precip_mm = double(doc["current"]["precip_mm"]);             // opady w mm
  746.         weather.precip_in = double(doc["current"]["precip_in"]);             // huj wie co to !!!
  747.         weather.humidity = doc["current"]["humidity"];                       // wilgotność powietrza
  748.         weather.cloud = doc["current"]["cloud"];                             // zachmurzenie %
  749.         weather.vis_km = double(doc["current"]["vis_km"]);                   // widzialnosc km
  750.         weather.vis_miles = double(doc["current"]["vis_miles"]);             // widzialnosc mile
  751.         weather.uv = double(doc["current"]["uv"]);                           // index UV
  752.  
  753.         WeatherUpdate = true;                                                // przestaw flagę na true
  754.  
  755.         /*
  756.          *  create temp_str_buffer from weather outside temperature
  757.          */
  758.  
  759.         if(weather.temp_c > 0 && weather.temp_c < 10) snprintf(weather.char_buffer, sizeof weather.char_buffer, "+%1.1fC", weather.temp_c);
  760.         else
  761.         if(weather.temp_c > 10) snprintf(weather.char_buffer, sizeof weather.char_buffer, "%1.1fC", weather.temp_c);
  762.         else
  763.         if(weather.temp_c == 0) snprintf(weather.char_buffer, sizeof weather.char_buffer, "0%1.1fC", weather.temp_c);
  764.         else
  765.         if(weather.temp_c < 0 && weather.temp_c > -10) snprintf(weather.char_buffer, sizeof weather.char_buffer, "%1.1fC", weather.temp_c);
  766.        
  767.         weather.temp_str_buffer = "Temp:" + String(weather.char_buffer);
  768.  
  769.         /*
  770.          *  create humi_str_buffer from weather outside humidity
  771.          */
  772.  
  773.         snprintf(weather.char_buffer, sizeof weather.char_buffer, "%d%%", weather.humidity);
  774.         weather.humi_str_buffer = "HumOut:" + String(weather.char_buffer);
  775.  
  776.          /*
  777.          *  create pressure_buffer from weather outside pressure
  778.          */
  779.  
  780.          snprintf(weather.char_buffer, sizeof weather.char_buffer, "%d hPa", weather.pressure_mb);
  781.          strcpy(weather.pressure_buffer, weather.char_buffer);
  782.  
  783.          /*
  784.          *  create cloud_buffer from weather outside cloud
  785.          */
  786.  
  787.          snprintf(weather.char_buffer, sizeof weather.char_buffer, "Cloud:%d%%", weather.cloud);
  788.          strcpy(weather.cloud_buffer, weather.char_buffer);
  789.  
  790.      
  791.         // --- update struct WEATHER in PSRAM !!! -------------------------------------------------- //
  792.              
  793.     }
  794. }
  795.  
  796. /***************************************************************************************************************/
  797. /*    
  798.     @definition    Task1Callback
  799. */
  800. /***************************************************************************************************************/
  801.  
  802. void Task1Callback()
  803. {
  804.     #if SERIAL
  805.         Serial.printf_P( PSTR ("\n+---------------------------------------------------------------------------------------+"));
  806.         #if ENGLISH
  807.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK1] Hello from Task1Callback :-)") );
  808.         #endif
  809.         #if POLISH
  810.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK1] Uruchomiono Task1Callback :-)") );
  811.         #endif
  812.         #if GERMANY
  813.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK1] Sie sind in Task1Callback :-)") );
  814.         #endif
  815.     #endif
  816.    
  817.     #if SERIAL
  818.         Serial.printf_P( PSTR( "\n\n[ESP] [TASK1] [Memory Free]     : %u [kB]" ), ESP.getFreeHeap());      
  819.         Serial.printf_P( PSTR( "\n[ESP] [TASK1] [CPU frequency]   : %u [MHz]" ),ESP.getCpuFreqMHz());  
  820.         Serial.printf_P( PSTR( "\n[ESP] [TASK1] [WiFi IP]         : " )); Serial.print(WiFi.localIP() );
  821.        
  822.         #if POLISH
  823.            Serial.printf("\n[ESP] [TASK1] [Local Time]      : ");
  824.            Serial.print(String() + timeClient.getStrHours() + ":"
  825.                                    + timeClient.getStrMinutes() + ":"
  826.                                    + timeClient.getStrSeconds() + " "
  827.                                    + DAY[timeClient.WeekDay()-1] + " "                                  
  828.                                    + timeClient.getDay() + "/"
  829.                                    + timeClient.getMonth() + "/"
  830.                                    + timeClient.getYear());          
  831.         #endif        
  832.         #if ENGLISH
  833.            Serial.printf("\n[ESP] [TASK1] [Local Time]      : ");
  834.            Serial.print(String() + timeClient.getStrHours() + ":"
  835.                                    + timeClient.getStrMinutes() + ":"
  836.                                    + timeClient.getStrSeconds() + " "
  837.                                    + DAY[timeClient.WeekDay()-1] + " "
  838.                                    + timeClient.getDay() + "/"
  839.                                    + timeClient.getMonth() + "/"
  840.                                    + timeClient.getYear());          
  841.        #endif        
  842.        #if GERMANY
  843.            Serial.printf("\n[ESP] [TASK1] [Local Time]      : ");
  844.            Serial.print(String() + timeClient.getStrHours() + ":"
  845.                                    + timeClient.getStrMinutes() + ":"
  846.                                    + timeClient.getStrSeconds() + " "
  847.                                    + DAY[timeClient.getWeek()-1] + " "
  848.                                    + timeClient.getDay() + "/"
  849.                                    + timeClient.getMonth() + "/"
  850.                                    + timeClient.getYear());          
  851.        #endif                              
  852.     #endif        
  853. }
  854.  
  855. /***************************************************************************************************************/
  856. /*    
  857.     @definition     Task2Callback
  858.     @interval       1 seconds
  859.     @function       update time only
  860. */
  861. /***************************************************************************************************************/
  862.  
  863. void Task2Callback()
  864. {
  865.     timeClient.update();                                        // update time
  866.      
  867.     if (timeClient.updated())
  868.     {
  869.         F_TimeUpdate = true;
  870.     }
  871.     else
  872.     {
  873.         #if SERIAL
  874.             Serial.printf_P( PSTR ("\n+---------------------------------------------------------------------------------------+"));
  875.             #if ENGLISH
  876.                 Serial.printf_P( PSTR ("\n\n[ESP] [TASK1] Hello from Task1Callback :-)") );
  877.             #endif
  878.             #if POLISH
  879.                 Serial.printf_P( PSTR ("\n\n[ESP] [TASK1] Uruchomiono Task1Callback :-)") );
  880.             #endif
  881.             #if GERMANY
  882.                 Serial.printf_P( PSTR ("\n\n[ESP] [TASK1] Sie sind in Task1Callback :-)") );
  883.             #endif
  884.             #if ENGLISH
  885.                 Serial.printf_P( PSTR ("\n[ESP] [TASK2] [Time Update]     : Wait"));
  886.             #endif
  887.             #if POLISH
  888.                 Serial.printf_P( PSTR ("\n[ESP] [TASK2] [Time Update]     : Czekaj"));
  889.             #endif
  890.             #if GERMANY
  891.                 Serial.printf_P( PSTR ("\n[ESP] [TASK2] [Time Update]     : Warten"));
  892.             #endif
  893.         #endif
  894.        
  895.         F_TimeUpdate = false;                            
  896.     }
  897.      
  898. }
  899.  
  900. /***************************************************************************************************************/
  901. /*    
  902.     @definition     Task3Callback
  903.     interval       10 minuts
  904.    
  905. */
  906. /***************************************************************************************************************/
  907.  
  908. void Task3Callback()
  909. {
  910.     #if SERIAL
  911.         Serial.printf_P( PSTR ("\n+---------------------------------------------------------------------------------------+"));
  912.         #if ENGLISH
  913.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK3] Hello from Task3Callback :-)") );
  914.         #endif
  915.         #if POLISH
  916.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK3] Uruchomiono Task3Callback :-)") );
  917.         #endif
  918.         #if GERMANY
  919.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK3] Sie sind in Task3Callback :-)") );
  920.         #endif
  921.     #endif
  922.  
  923.     if (timeClient.updated())
  924.     {
  925.  
  926.         /*          
  927.         *  tworzy sformatowaną datę (format String) w postaci dd/mm/yyyy
  928.         */
  929.  
  930.         if( timeClient.getDay() < 10 ) MyClock.formated_date = "0" + String(timeClient.getDay()) + "/";
  931.         else                           MyClock.formated_date = String(timeClient.getDay()) + "/";
  932.  
  933.         if( timeClient.getMonth() < 10 )  MyClock.formated_date += "0" + String(timeClient.getMonth()) + "/";
  934.         else                              MyClock.formated_date += String(timeClient.getMonth()) + "/";
  935.            
  936.         MyClock.formated_date += String(timeClient.getYear());    
  937.  
  938.         MyClock.DayOfTheWeek = timeClient.WeekDay()-1;
  939.  
  940.         #if SERIAL
  941.             #if ENGLISH
  942.                 Serial.printf_P( PSTR ("\n[ESP] [TASK4] Create Formated Date : %s "), MyClock.formated_date.c_str());
  943.             #endif
  944.             #if POLISH
  945.                 Serial.printf_P( PSTR ("\n[ESP] [TASK4] Utworzono Sformatowaną Datę :%s "), MyClock.formated_date.c_str());
  946.             #endif
  947.         #endif  
  948.          
  949.      }
  950. }
  951.  
  952. /***************************************************************************************************************/
  953. /*    
  954.     @definition    Task4Callback
  955.     @function      get & show temperature & humidity
  956. */
  957. /***************************************************************************************************************/
  958.  
  959. void Task4Callback()
  960. {
  961.    #if SERIAL
  962.         Serial.printf_P( PSTR ("\n+---------------------------------------------------------------------------------------+"));
  963.         #if ENGLISH
  964.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK4] Hello from Task4Callback :-)") );
  965.         #endif
  966.         #if POLISH
  967.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK4] Uruchomiono Task4Callback :-)") );
  968.         #endif
  969.         #if GERMANY
  970.             Serial.printf_P( PSTR ("\n\n[ESP] [TASK4] Sie sind in Task4Callback :-)") );
  971.         #endif
  972.     #endif
  973.  
  974.     int chk = DHT11.read();
  975.  
  976.     #if SERIAL
  977.         #if ENGLISH
  978.             Serial.printf_P( PSTR ("\nRead DHT11 sensor : ") );    
  979.         #endif
  980.         #if POLISH
  981.             Serial.printf_P( PSTR ("\nOdczyt z sensora DHT11 : ") );
  982.         #endif
  983.         #if GERMANY
  984.             Serial.printf_P( PSTR ("\nSensorwert DHT11 : ") );
  985.         #endif
  986.     #endif
  987.  
  988.     #if SERIAL
  989.         switch (chk)
  990.         {
  991.             case  0:
  992.                     Serial.printf_P( PSTR ("OK") );                    
  993.                     break;
  994.            
  995.             case -1:
  996.                 #if ENGLISH
  997.                     Serial.printf_P( PSTR ("Checksum error") ); break;
  998.                 #endif                
  999.                 #if POLISH
  1000.                     Serial.printf_P( PSTR ("Błąd sumy kontrolnej") ); break;
  1001.                 #endif
  1002.                 #if GERMANY
  1003.                     Serial.printf_P( PSTR ("Prüfsummenfehler") ); break;
  1004.                 #endif
  1005.            
  1006.             case -2:
  1007.                 #if ENGLISH
  1008.                     Serial.printf_P( PSTR ("Time out error") ); break;
  1009.                 #endif                
  1010.                 #if POLISH
  1011.                     Serial.printf_P( PSTR ("Błąd przekroczenia limitu czasu") ); break;
  1012.                 #endif
  1013.                 #if GERMANY
  1014.                     Serial.printf_P( PSTR ("Zeitüberschreitungsfehler") ); break;
  1015.                 #endif            
  1016.            
  1017.             default:
  1018.                 #if ENGLISH
  1019.                     Serial.printf_P( PSTR ("Unknown error") ); break;
  1020.                 #endif                
  1021.                 #if POLISH
  1022.                     Serial.printf_P( PSTR ("Nieznany błąd") ); break;
  1023.                 #endif
  1024.                 #if GERMANY
  1025.                     Serial.printf_P( PSTR ("Unbekannter Fehler") ); break;
  1026.                 #endif      
  1027.         }   // end switch
  1028.     #endif
  1029.  
  1030.     /*
  1031.      *  copy DHT11 temperature, humidity, devPoint to data in structure mydht
  1032.      *  kopiowanie DHT 11 temperatura, wilgotność, punkt zerowy do danych w strukturze mydht
  1033.      */
  1034.      
  1035.     mydht.inside_temperature = (float)DHT11.temperature;
  1036.     if(mydht.inside_temperature != mydht.prev_inside_temperature) F_temp = true;    // jeśli zmieniła się temperatura ustaw flagę na true
  1037.    
  1038.    
  1039.     mydht.inside_humidity = DHT11.humidity;
  1040.     if(mydht.inside_humidity != mydht.prev_inside_humidity) F_humi = true;          // jeśli zmieniała się wilgotność ustaw flagę na true
  1041.    
  1042.     mydht.inside_devpoint = (float)DHT11.dewPoint();    
  1043.  
  1044.     /*
  1045.      *  jeśli włączony SERIAL wydrukuj odczyty na terminalu SERIAL
  1046.      *  if SERIAL is TRUE print sensor-read on terminal SERIAL
  1047.      */
  1048.  
  1049.     #if SERIAL
  1050.         #if ENGLISH
  1051.            
  1052.             if(F_temp)
  1053.             {
  1054.                 Serial.printf_P( PSTR ("\nINSIDE Temperature Now    : %0.1f °C"), mydht.inside_temperature );
  1055.                 Serial.printf_P( PSTR ("\nINSIDE Temperature Before : %0.1f °C"), mydht.prev_inside_temperature );                
  1056.             }
  1057.             else
  1058.             {
  1059.                 Serial.printf_P( PSTR ("\nINSIDE Temperature        : %0.1f °C"), mydht.inside_temperature );                
  1060.             }  
  1061.  
  1062.             if(F_humi)
  1063.             {
  1064.                 Serial.printf_P( PSTR ("\nINSIDE Humidity Now       : %d %%"), mydht.inside_humidity );                        
  1065.                 Serial.printf_P( PSTR ("\nINSIDE Humidity Before    : %d %%"), mydht.prev_inside_humidity );                        
  1066.             }
  1067.             else
  1068.             {
  1069.                 Serial.printf_P( PSTR ("\nINSIDE Humidity           : %d %%"), mydht.inside_humidity );  
  1070.             }
  1071.            
  1072.             Serial.printf_P( PSTR ("\nINSIDE DevPoint           : %0.1f °C"), mydht.inside_devpoint );
  1073.            
  1074.         #endif
  1075.        
  1076.         #if POLISH
  1077.            
  1078.             if(F_temp)
  1079.             {
  1080.                 Serial.printf_P( PSTR ("\nWEWNĄTRZ Temperatura Teraz      : %0.1f °C"), mydht.inside_temperature );  
  1081.                 Serial.printf_P( PSTR ("\nWEWNĄTRZ Temperatura Poprzednio : %0.1f °C"), mydht.prev_inside_temperature );  
  1082.             }
  1083.             else
  1084.             {        
  1085.                 Serial.printf_P( PSTR ("\nWEWNĄTRZ Temperatura            : %0.1f °C"), mydht.inside_temperature );                
  1086.             }
  1087.  
  1088.             if(F_humi)
  1089.             {
  1090.                 Serial.printf_P( PSTR ("\nWEWNĄTRZ Wilgotność Teraz       : %d %%"), mydht.inside_humidity );
  1091.                 Serial.printf_P( PSTR ("\nWEWNĄTRZ Wilgotność Poprzednio  : %d %%"), mydht.prev_inside_humidity );
  1092.             }
  1093.             else
  1094.             {
  1095.                 Serial.printf_P( PSTR ("\nWEWNĄTRZ Wilgotność             : %d %%"), mydht.inside_humidity );
  1096.             }            
  1097.            
  1098.             Serial.printf_P( PSTR ("\nWEWNĄTRZ Punkt ZERO             : %0.1f °C"), mydht.inside_devpoint );
  1099.            
  1100.         #endif
  1101.        
  1102.         #if GERMANY
  1103.        
  1104.             Serial.printf_P( PSTR ("\nInnen temperatur                   : %0.1f °C"), mydht.inside_temperature );
  1105.             Serial.printf_P( PSTR ("\ninnere Feuchtigkeit                : %d %%"), mydht.inside_humidity );
  1106.             Serial.printf_P( PSTR ("\ninnerhalb des Entwicklungspunktes  : %0.1f °C"), mydht.inside_devpoint );
  1107.            
  1108.         #endif      
  1109.     #endif
  1110.    
  1111.     /*
  1112.      *  konwersja float (temperature) do char[20] buffer
  1113.      *  rzutowanie typów char[20] buffer do String -> mydht.buf_temperature
  1114.      */
  1115.      
  1116.     snprintf(mydht.temp_char_buffer, sizeof mydht.temp_char_buffer, "%1.1fC", mydht.inside_temperature);
  1117.     mydht.buf_temperature = "Room:" + String(mydht.temp_char_buffer);
  1118.  
  1119.     #if DEBUG
  1120.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.temp_char_buffer : %s"), mydht.temp_char_buffer);
  1121.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.buf_temperature  : %s"), mydht.buf_temperature);
  1122.     #endif
  1123.  
  1124.     /*
  1125.      *  konwersja float (humidity) do char[20] buffer
  1126.      *  rzutowanie typów char[20] buffer do String -> mydht.buf_temperature
  1127.      */
  1128.      
  1129.     snprintf(mydht.temp_char_buffer, sizeof mydht.temp_char_buffer, "%d%%", mydht.inside_humidity);
  1130.     mydht.buf_humidity = "HumIn:" + String(mydht.temp_char_buffer);
  1131.  
  1132.     #if DEBUG
  1133.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.temp_char_buffer : %s"), mydht.temp_char_buffer);
  1134.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.buf_humidity     : %s"), mydht.buf_humidity);
  1135.     #endif
  1136.  
  1137.     /*
  1138.      *  konwersja float (humidity) do char[20] buffer
  1139.      *  rzutowanie typów char[20] buffer do String -> mydht.buf_temperature
  1140.      */
  1141.      
  1142.     snprintf(mydht.temp_char_buffer, sizeof mydht.temp_char_buffer, "%0.1fC", mydht.inside_devpoint);
  1143.     mydht.buf_devpoint = "DevP:" + String(mydht.temp_char_buffer);
  1144.  
  1145.     #if DEBUG
  1146.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> mydht.temp_char_buffer : %s"), mydht.temp_char_buffer);
  1147.         Serial.printf_P( PSTR ("\n[DEBUG] Zawartość zmiennej ---> buf_devpoint           : %s"), mydht.buf_devpoint);
  1148.     #endif
  1149. }
  1150.  
  1151. /***************************************************************************************************************/
  1152. /*    
  1153.     @definition    statWiFi()
  1154. */
  1155. /***************************************************************************************************************/
  1156.  
  1157. void statWiFi()
  1158. {
  1159.     switch (WiFi.status())
  1160.     {
  1161.         case WL_NO_SSID_AVAIL:
  1162.                               #if SERIAL
  1163.                                   #if ENGLISH
  1164.                                       Serial.printf_P ( PSTR ("\nConfigured SSID cannot be reached"));
  1165.                                   #endif
  1166.                                   #if POLISH
  1167.                                       Serial.printf_P ( PSTR ("\nNie można osiągnąć skonfigurowanego identyfikatora SSID"));
  1168.                                   #endif
  1169.                                   #if GERMANY
  1170.                                       Serial.printf_P ( PSTR ("\nKonfigurierte SSID ist nicht erreichbar"));
  1171.                                   #endif
  1172.                               #endif        
  1173.                               break;
  1174.                              
  1175.         case WL_CONNECTED:
  1176.                               #if SERIAL
  1177.                                   #if ENGLISH
  1178.                                       Serial.printf_P ( PSTR ("\nConnection successfully established"));
  1179.                                       Serial.printf_P ( PSTR ("\nYour IP : %s"), WiFi.localIP().toString().c_str());
  1180.                                       Serial.printf_P ( PSTR ("\nReceived Signal Strength Indication : %d"), WiFi.RSSI());
  1181.                                   #endif
  1182.                                   #if POLISH
  1183.                                       Serial.printf_P ( PSTR ("\nPomyślnie nawiązano połączenie"));
  1184.                                       Serial.printf_P ( PSTR ("\nTwój adres IP : %s"), WiFi.localIP().toString().c_str());
  1185.                                       Serial.printf_P ( PSTR ("\nWskazanie siły odbieranego sygnału : %d"), WiFi.RSSI());
  1186.                                   #endif
  1187.                                   #if GERMANY
  1188.                                       Serial.printf_P( PSTR ("\nVerbindung erfolgreich hergestellt"));
  1189.                                       Serial.printf_P( PSTR ("\nDeine IP-Adresse : %s"), WiFi.localIP().toString().c_str());
  1190.                                       Serial.printf_P( PSTR ("\nAnzeige der empfangenen Signalstärke : %d"), WiFi.RSSI());                                
  1191.                                   #endif
  1192.                               #endif
  1193.                               break;
  1194.                              
  1195.         case WL_CONNECT_FAILED:
  1196.                               #if SERIAL
  1197.                                   #if ENGLISH
  1198.                                       Serial.printf_P( PSTR ("\nConnection failed"));
  1199.                                   #endif
  1200.                                   #if POLISH
  1201.                                       Serial.printf_P( PSTR ("\nPołączenie nieudane"));
  1202.                                   #endif
  1203.                                   #if GERMANY
  1204.                                       Serial.printf_P( PSTR ("\nVerbindung fehlgeschlagen"));
  1205.                                   #endif
  1206.                               #endif
  1207.                               break;
  1208.       }      
  1209. }
  1210.  
  1211. /***************************************************************************************************************/
  1212. /*    
  1213.     @definition    initWiFi()
  1214. */
  1215. /***************************************************************************************************************/
  1216.  
  1217. void initWiFi()
  1218. {
  1219.     WiFi.mode(WIFI_STA);
  1220.     WiFi.begin(ssid, password);
  1221.  
  1222.     const char * msg1 = "Wi-Fi";                                        // zapakuj do pamięci PROGMEM    
  1223.     const char * msg2 = "conecting";                                    // zapakuj do pamięci PROGMEM    
  1224.     DisplayReset();                                                     // wymaż ekran (kolor czarny)    
  1225.     display.setTextColor(myBLUE);                                       // ustaw kolor znaków
  1226.     display.setTextSize(2);                                             // ustaw wielkość znaków        
  1227.     display.setCursor(3,0);                                             // ustaw kursor        
  1228.     MatrixTypeWriter(msg1,200);                                         // wyświetl msg1 (typewriter)
  1229.     display.setTextColor(myGREEN);                                      // ustaw kolor znaków
  1230.     display.setTextSize(1);                                             // ustaw wielkość znaków        
  1231.     display.setCursor(5,16);                                            // ustaw kursor        
  1232.     MatrixTypeWriter(msg2,200);                                         // wyświetl msg1 (typewriter)    
  1233.     delay(3000);                                                        // poczekaj chwile    
  1234.  
  1235.     #if SERIAL    
  1236.         #if ENGLISH
  1237.             Serial.printf_P( PSTR ("\n[DEBUG] Connecting to WiFi .."));
  1238.         #endif
  1239.         #if POLISH
  1240.             Serial.printf_P( PSTR ( "\n[DEBUG] Łącze z siecią WiFi .."));
  1241.         #endif
  1242.         #if GERMANY
  1243.             Serial.printf_P( PSTR ("\n[DEBUG] Netzwerkverbindung mit WLAN .."));
  1244.         #endif
  1245.     #endif
  1246.      
  1247.     while (WiFi.status() != WL_CONNECTED)
  1248.     {
  1249.         Serial.printf_P( PSTR( "." ));
  1250.         delay(200);
  1251.     }
  1252.  
  1253.     statWiFi();
  1254.          
  1255.     WiFi.setAutoReconnect(true);
  1256.     WiFi.persistent(true);
  1257. }
  1258.  
  1259. /***************************************************************************************************************/
  1260. /*    
  1261.     @definition    reconectWifi()
  1262. */
  1263. /***************************************************************************************************************/
  1264.  
  1265. void reconectWifi()
  1266. {
  1267.     unsigned long currentMillis = millis();
  1268.      
  1269.     if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval))
  1270.     {
  1271.         #if SERIAL
  1272.             #if ENGLISH
  1273.                 Serial.printf_P( PSTR ( "\n[DEBUG] Reconnecting to WiFi..."));
  1274.             #endif
  1275.             #if POLISH
  1276.                 Serial.printf_P( PSTR ( "\n[DEBUG] Ponowne łączenie z Wi-Fi..."));
  1277.             #endif
  1278.             #if GERMANY
  1279.                 Serial.printf_P( PSTR ( "\n[DEBUG] Erneut mit WLAN verbinden..."));
  1280.             #endif
  1281.         #endif
  1282.          
  1283.         WiFi.disconnect();
  1284.         WiFi.begin(ssid, password);
  1285.          
  1286.         statWiFi();
  1287.          
  1288.         previousMillis = currentMillis;
  1289.     }
  1290. }
  1291.  
  1292. /***************************************************************************************************************/
  1293. /*    
  1294.     @definition    SerialTypeWriter
  1295. */
  1296. /***************************************************************************************************************/
  1297.  
  1298. void SerialTypeWriter(const String & message, unsigned int wait)
  1299. {
  1300.     for(const char c : message)
  1301.     {
  1302.         Serial.print(c);    
  1303.         delay(wait);  
  1304.     }
  1305. }
  1306.  
  1307. /***************************************************************************************************************/
  1308. /*    
  1309.     @definition    SerialTypeWriter
  1310. */
  1311. /***************************************************************************************************************/
  1312.  
  1313. void MatrixTypeWriter(const String & message, unsigned int wait)
  1314. {
  1315.     #if SERIAL
  1316.         #if ENGLISH
  1317.             Serial.printf_P( PSTR ("\n[DEBUG] Show message on PxMatrix : "));
  1318.         #endif
  1319.         #if POLISH
  1320.             Serial.printf_P( PSTR ("\n[DEBUG] Pokazuję wiadomość na PxMatrix : "));
  1321.         #endif
  1322.         #if GERMANY
  1323.             Serial.printf_P( PSTR ("\n[DEBUG] Nachricht anzeigen an PxMatrix : "));
  1324.         #endif
  1325.     #endif
  1326.  
  1327.     for(const char c : message)
  1328.     {
  1329.         display.print(c);    
  1330.        
  1331.         #if SERIAL
  1332.             Serial.print(c);
  1333.         #endif
  1334.        
  1335.         delay(wait);  
  1336.     }
  1337. }
  1338.  
  1339. /***************************************************************************************************************/
  1340. /*    
  1341.     @definition    MorphingClock
  1342. */
  1343. /***************************************************************************************************************/
  1344.  
  1345. void MorphingClock()
  1346. {
  1347.     unsigned long epoch = timeClient.getEpochTime();  
  1348.  
  1349.     static int color_int = 1;
  1350.  
  1351.     if (epoch != prevEpoch)
  1352.     {
  1353.         int hh = timeClient.getHours();
  1354.         int mm = timeClient.getMinutes();
  1355.         int ss = timeClient.getSeconds();      
  1356.    
  1357.         if (prevEpoch == 0)
  1358.         {
  1359.             digit0.Draw(ss % 10);
  1360.             digit1.Draw(ss / 10);
  1361.             digit2.Draw(mm % 10);
  1362.             digit3.Draw(mm / 10);
  1363.             digit4.Draw(hh % 10);
  1364.             digit5.Draw(hh / 10);
  1365.          }
  1366.          else
  1367.          {      
  1368.             if (ss!=prevss)
  1369.             {
  1370.                 int s0 = ss % 10;
  1371.                 int s1 = ss / 10;
  1372.                 if (s0!=digit0.Value()) digit0.Morph(s0);
  1373.                 if (s1!=digit1.Value()) digit1.Morph(s1);        
  1374.                 prevss = ss;
  1375.  
  1376.                 uint16_t myB;
  1377.                
  1378.                 if    (color_int)
  1379.                 {
  1380.                     color_int=0;
  1381.                     myB = myBlue0;
  1382.                 }
  1383.                 else              
  1384.                 {
  1385.                     color_int=1;
  1386.                     myB = myBLACK;
  1387.                 }
  1388.  
  1389.                 display.drawPixel(20,13,myB);
  1390.                 display.drawPixel(21,13,myB);
  1391.                 display.drawPixel(20,14,myB);
  1392.                 display.drawPixel(21,14,myB);
  1393.                 display.drawPixel(20,18,myB);
  1394.                 display.drawPixel(21,18,myB);
  1395.                 display.drawPixel(20,19,myB);
  1396.                 display.drawPixel(21,19,myB);
  1397.  
  1398.                 display.drawPixel(41,13,myB);
  1399.                 display.drawPixel(42,13,myB);
  1400.                 display.drawPixel(41,14,myB);
  1401.                 display.drawPixel(42,14,myB);
  1402.                 display.drawPixel(41,18,myB);
  1403.                 display.drawPixel(42,18,myB);
  1404.                 display.drawPixel(41,19,myB);
  1405.                 display.drawPixel(42,19,myB);
  1406.             }
  1407.  
  1408.             /*************************************************************************
  1409.              *  jeśli zmieniła się minuta
  1410.              ************************************************************************/
  1411.              
  1412.             if (mm!=prevmm)
  1413.             {
  1414.                 int m0 = mm % 10;
  1415.                 int m1 = mm / 10;
  1416.                 if (m0!=digit2.Value()) digit2.Morph(m0);
  1417.                 if (m1!=digit3.Value()) digit3.Morph(m1);                
  1418.  
  1419.                 /*
  1420.                  *  multi-display
  1421.                  *  wyswietla informacje na górnym obszarze
  1422.                  */                
  1423.  
  1424.                 byte multi = m0 % 4;                                                    // wyznacz resztę z dzielenia (minuta modulo 4)
  1425.                 byte pos   = 32-(strlen(Weekday[MyClock.DayOfTheWeek])*3);              // wyznacz pozycję x na ekranie dla dnia tygodnia
  1426.                 byte pre   = 32-(strlen(weather.pressure_buffer)*3);                    // wyznacz pozycje x na ekranie dla cisnienia atmosferycznego
  1427.  
  1428.                 switch(multi)
  1429.                 {
  1430.                     /*
  1431.                      * jeśli reszta z dzielenia = '0'
  1432.                      */
  1433.                
  1434.                     case 0:  
  1435.                             // ----------------------------------------------------------------------------------------------------------------
  1436.                             display.fillRect(0,0,64,8,myBLACK);                               // wymaż obszar roboczy
  1437.                             display.setTextColor(myGREEN);                                    // ustaw kolor tekstu na zielony
  1438.                             display.setCursor(2,0);                                           // ustaw kursor
  1439.                             display.print(MyClock.formated_date.c_str());                     // wyswietl sformatowana datę dd/mm/yyyy z bufora
  1440.                             // ----------------------------------------------------------------------------------------------------------------
  1441.                             display.fillRect(0,24,64,32,myBLACK);                             // wymaż obszar roboczy              
  1442.                             display.setCursor(pos,24);                                        // ustaw kursor
  1443.                             display.setTextColor(myGREEN2);                            
  1444.                             display.print(Weekday[MyClock.DayOfTheWeek]);                     // wyświetl dzień tygodnia (po angielsku)
  1445.                             // ----------------------------------------------------------------------------------------------------------------    
  1446.                             break;
  1447.  
  1448.                     /*
  1449.                      * jeśli reszta z dzielenia = '1'
  1450.                      * wyświetl (góra) wilgotność powietrza na zewnątrz (pobrane z open.weather.map)
  1451.                      * wyświetl (dół) temperaturę powietrza na zewnątrz (pobrane z open.weather.map)
  1452.                      */        
  1453.  
  1454.                     case 1:
  1455.                             // ----------------------------------------------------------------------------------------------------------------
  1456.                             display.fillRect(0,0,64,8,myBLACK);                               // wymaż obszar roboczy
  1457.                             display.setTextColor(myDarkRed2);                                 // ustaw kolor tekstu
  1458.                             display.setCursor(2,0);                                           // ustaw kursor
  1459.                             display.print(weather.humi_str_buffer.c_str());                   // wyswietl sformatowana wilgotnosc (out)z bufora                            
  1460.                             // ----------------------------------------------------------------------------------------------------------------
  1461.                             display.fillRect(0,24,64,32,myBLACK);                             // wymaż obszar roboczy              
  1462.                             display.setCursor(2,24);                                          // ustaw kursor
  1463.                             display.setTextColor(myDarkRed4);                                 // ustaw kolor
  1464.                             display.print(weather.temp_str_buffer.c_str());                   // wyświetl temperature
  1465.                             F_humi = false;                                                   // przestaw flagę na false
  1466.                             // ----------------------------------------------------------------------------------------------------------------
  1467.                             break;
  1468.  
  1469.                     /*
  1470.                      * jeśli reszta z dzielenia = '2'
  1471.                      * wyświetl (góra) wilgotność powietrza wewnątrz (pobrane z czujnika dht11)
  1472.                      * wyświetl (dół) temperaturę powietrza wewnątrz (pobrane z czujnika dht11)
  1473.                      */
  1474.                    
  1475.                     case 2:
  1476.                             // ----------------------------------------------------------------------------------------------------------------
  1477.                             display.fillRect(0,0,64,8,myBLACK);                                 // wymaż obszar roboczy
  1478.                             display.setTextColor(myDarkRed2);                                   // ustaw kolor tekstu
  1479.                             display.setCursor(5,0);                                             // ustaw kursor
  1480.                             display.print(mydht.buf_humidity.c_str());                          // wyswietl sformatowana wilgotnosc z bufora
  1481.                             mydht.prev_inside_humidity = mydht.inside_humidity;                 // zapisz nową wilgotnosc (na wszelki wypadek)
  1482.                             // ----------------------------------------------------------------------------------------------------------------
  1483.                             display.fillRect(0,24,64,32,myBLACK);                               // wymaż obszar roboczy              
  1484.                             display.setCursor(2,24);                                            // ustaw kursor
  1485.                             display.setTextColor(myDarkRed4);                                   // ustaw kolor
  1486.                             display.print(mydht.buf_temperature.c_str());                       // wyświetl temperature
  1487.                             mydht.prev_inside_temperature = mydht.inside_temperature;           // zapisz nową temperaturę          
  1488.                             // ----------------------------------------------------------------------------------------------------------------
  1489.                             break;                        
  1490.  
  1491.                     /*
  1492.                      * jeśli reszta z dzielenia = '3'
  1493.                      * wyświetl (góra) zachmurzenie % (pobrane z apiweather.com)
  1494.                      * wyświetl (dół)  ciśnienie atmosferyczny mPa (pobrane z apiweather.com)
  1495.                      */
  1496.                    
  1497.                     case 3:
  1498.                             // ----------------------------------------------------------------------------------------------------------------
  1499.                             display.fillRect(0,0,64,8,myBLACK);                                 // wymaż obszar roboczy
  1500.                             display.setTextColor(myDarkRed2);                                   // ustaw kolor tekstu
  1501.                             display.setCursor(2,0);                                             // ustaw kursor
  1502.                             display.print(weather.cloud_buffer);                               // wyswietl sformatowana wilgotnosc z bufora                            
  1503.                             // ----------------------------------------------------------------------------------------------------------------
  1504.                             display.fillRect(0,24,64,32,myBLACK);                               // wymaż obszar roboczy              
  1505.                             display.setCursor(pre,24);                                          // ustaw kursor
  1506.                             display.setTextColor(myDarkRed4);                                   // ustaw kolor
  1507.                             display.print(weather.pressure_buffer);                             // wyświetl temperature                        
  1508.                             // ----------------------------------------------------------------------------------------------------------------    
  1509.                             break;
  1510.                 }
  1511.  
  1512.                
  1513.            
  1514.                 prevmm = mm;
  1515.              
  1516.              }
  1517.  
  1518.              /*************************************************************************
  1519.              *  jeśli zmieniła się godzina
  1520.              ************************************************************************/
  1521.                    
  1522.              if (hh!=prevhh)
  1523.              {
  1524.                 int h0 = hh % 10;
  1525.                 int h1 = hh / 10;
  1526.                 if (h0!=digit4.Value()) digit4.Morph(h0);
  1527.                 if (h1!=digit5.Value()) digit5.Morph(h1);
  1528.                 prevhh = hh;
  1529.              }
  1530.         }
  1531.         prevEpoch = epoch;
  1532.     }  
  1533. }
  1534.  
  1535. /***************************************************************************************************************/
  1536. /*    
  1537.     @definition    ShowInfo
  1538. */
  1539. /***************************************************************************************************************/
  1540.  
  1541. void ShowInfo()
  1542. {
  1543.     Serial.printf_P( PSTR ("\n+-------------------------------------------------------------+"));
  1544.     Serial.printf_P( PSTR ("\n|        Morphing Clock %s final by Tomasz Majcher          |" ),version);    
  1545.     Serial.printf_P( PSTR ("\n|          ESP8266 + PxMatrix + DHT11 + ApiWeather            |" ));      
  1546.     Serial.printf_P( PSTR ("\n|                                                             |" ));      
  1547.     Serial.printf_P( PSTR ("\n|        e-mail: [email protected]                  |" ));      
  1548.     Serial.printf_P( PSTR ("\n+-------------------------------------------------------------+\n"));
  1549. }
  1550.  
  1551. /***************************************************************************************************************/
  1552. /*    
  1553.     @definition   DisplayReset
  1554.                   clear display * set font size 1
  1555. */
  1556. /***************************************************************************************************************/
  1557.  
  1558. void DisplayReset()
  1559. {
  1560.     display.setTextSize(1);                                             // przywroc domyslne ustawienia wielkosci znaków
  1561.     display.fillScreen(display.color565(0, 0, 0));                      // wymaż ekran (kolor czarny)      
  1562. }
  1563.  
  1564. /***************************************************************************************************************/
  1565. /*    
  1566.     @definition   DisplayInit
  1567. */
  1568. /***************************************************************************************************************/
  1569.  
  1570. void DisplayStart()
  1571. {
  1572.     const char * msg1 = "Hello";                                        // zapakuj do pamięci PROGMEM
  1573.     const char * msg2 = "Tomek";                                        // zapakuj do pamięci PROGMEM
  1574.    
  1575.     display.begin(16);                                                  // ustaw wyswietlacz
  1576.     display_update_enable(true);                                        // ustaw auto update
  1577.    
  1578.     DisplayReset();                                                     // wymaż ekran (kolor czarny)    
  1579.     display.setTextColor(myBLUE);                                       // ustaw kolor znaków
  1580.     display.setTextSize(2);                                             // ustaw wielkość znaków    
  1581.    
  1582.     display.setCursor(3,0);                                             // ustaw kursor        
  1583.     MatrixTypeWriter(msg1,200);                                         // wyświetl msg1 (typewriter)
  1584.    
  1585.     display.setCursor(3,16);                                            // ustaw kursor    
  1586.     MatrixTypeWriter(msg2,200);                                         // wyświetl msg2 (typewriter)            
  1587.    
  1588.     delay(3000);                                                        // poczekaj chwile
  1589.    
  1590.     DisplayReset();                                                     // wymaż ekran (kolor czarny)    
  1591.    
  1592. }
  1593.  
  1594. /***************************************************************************************************************/
  1595. /*    
  1596.     @definition    setup
  1597. */
  1598. /***************************************************************************************************************/
  1599.  
  1600. void setup()
  1601. {
  1602.     delay(300);                                          // rozruch, chwila przerwy ...
  1603.    
  1604.     #if SERIAL      
  1605.         Serial.begin(SerialSpeed);
  1606.         ShowInfo();
  1607.     #endif  
  1608.    
  1609.     DisplayStart();
  1610.  
  1611.     DHT11.attach(DHT_PIN);                                // DHT11 sensor start
  1612.        
  1613.     initWiFi();                                           // start Wi-Fi  
  1614.  
  1615.     timeClient.begin();    
  1616.     runner.init();                                        // inicjalizuj scheluder                                                                                    
  1617.     runner.addTask(task_0);                               // dodaj zadanie do scheluder
  1618.     task_0.enable();                                      // włącz zadanie do scheluder
  1619.     runner.addTask(task_1);                               // dodaj zadanie do scheluder
  1620.     task_1.enable();                                      // włącz zadanie do scheluder
  1621.     runner.addTask(task_2);                               // dodaj zadanie do scheluder
  1622.     task_2.enable();                                      //  włącz zadanie do scheluder
  1623.     runner.addTask(task_3);                               // dodaj zadanie do scheluder
  1624.     task_3.enable();                                      // włącz zadanie do scheluder
  1625.     runner.addTask(task_4);                               // dodaj zadanie do scheluder
  1626.     task_4.enable();                                      // włącz zadanie do scheluder
  1627.      
  1628.      // --- WYWOŁAJ TERAZ --------------------- //
  1629.  
  1630.     DisplayReset();
  1631.    
  1632.     Task1Callback();  
  1633.     Task2Callback();  
  1634.     Task3Callback();    
  1635.     Task4Callback();    
  1636.     Task4Callback();    
  1637.     Task4Callback();    
  1638. }
  1639.  
  1640. /***************************************************************************************************************/
  1641. /*    
  1642.     @main    loop program
  1643. */
  1644. /***************************************************************************************************************/
  1645.  
  1646.  
  1647. void loop()
  1648. {
  1649.     runner.execute();     // scheluder init
  1650.     reconectWifi();       // check Wi-Fi status
  1651.     MorphingClock();
  1652.     if(WeatherUpdate) WeatherShow();
  1653.  
  1654. }
  1655.  
  1656. /***************************************************************************************************************/
  1657. /*    
  1658.     @main    loop program
  1659. */
  1660. /***************************************************************************************************************/
  1661.  
  1662. void WeatherShow()
  1663. {
  1664.     #if DEBUG_WEATHER  
  1665.         #if SERIAL
  1666.             Serial.printf_P( PSTR ("\n+---------------------------------------------------------------------------------------+"));
  1667.             #if ENGLISH
  1668.                 Serial.printf_P( PSTR ("\n[API] [Weather] City             : %s"), weather.city);
  1669.                 Serial.printf_P( PSTR ("\n[API] [Weather] Country          : %s"), weather.country);
  1670.                 Serial.printf_P( PSTR ("\n[API] [Weather] TZ ID            : %s"), weather.tz_id);
  1671.                 Serial.printf_P( PSTR ("\n[API] [Weather] Latitude         : %0.2f"), weather.lat);
  1672.                 Serial.printf_P( PSTR ("\n[API] [Weather] Longitude        : %0.2f"), weather.lon);
  1673.                 Serial.printf_P( PSTR ("\n[API] [Weather] Epoch Time       : %d"), weather.localtime_epoch);
  1674.                 Serial.printf_P( PSTR ("\n[API] [Weather] Localtime        : %s"), weather.localtime);
  1675.                 Serial.printf_P( PSTR ("\n[API] [Weather] Last Updade      : %s"), weather.last_updated);
  1676.                 Serial.printf_P( PSTR ("\n[API] [Weather] Temp C           : %0.2f"), weather.temp_c);
  1677.                 Serial.printf_P( PSTR ("\n[API] [Weather] Temp feel C      : %0.2f"), weather.feelslike_c);
  1678.                 Serial.printf_P( PSTR ("\n[API] [Weather] Temp F           : %0.2f"), weather.temp_f);
  1679.                 Serial.printf_P( PSTR ("\n[API] [Weather] Temp feel F      : %0.2f"), weather.feelslike_f);
  1680.                 Serial.printf_P( PSTR ("\n[API] [Weather] Condition EN     : %s"), weather.condition_en);
  1681.                 Serial.printf_P( PSTR ("\n[API] [Weather] Condition PL     : %s"), weather.condition_pl);
  1682.                 Serial.printf_P( PSTR ("\n[API] [Weather] icon             : %s"), weather.icon);
  1683.                 Serial.printf_P( PSTR ("\n[API] [Weather] icon code        : %d"), weather.code);
  1684.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind speed kph   : %0.2f"), weather.wind_kph);
  1685.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind gust kph    : %0.2f"), weather.gust_kph);
  1686.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind speed mph   : %0.2f"), weather.wind_mph);
  1687.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind gust mph    : %0.2f"), weather.gust_mph);
  1688.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind degree      : %d"), weather.wind_degree);
  1689.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind dir         : %s"), weather.wind_dir);
  1690.                 Serial.printf_P( PSTR ("\n[API] [Weather] Pressure mb      : %d"), weather.pressure_mb);
  1691.                 Serial.printf_P( PSTR ("\n[API] [Weather] Pressure in      : %0.2f"), weather.pressure_in);
  1692.                 Serial.printf_P( PSTR ("\n[API] [Weather] Precip mm        : %0.2f"), weather.precip_mm);
  1693.                 Serial.printf_P( PSTR ("\n[API] [Weather] Precip in        : %0.2f"), weather.precip_in);
  1694.                 Serial.printf_P( PSTR ("\n[API] [Weather] Humidity         : %d"), weather.humidity);
  1695.                 Serial.printf_P( PSTR ("\n[API] [Weather] Cloud            : %d"), weather.cloud);
  1696.                 Serial.printf_P( PSTR ("\n[API] [Weather] Vis km           : %0.2f"), weather.vis_km);
  1697.                 Serial.printf_P( PSTR ("\n[API] [Weather] Vis miles        : %0.2f"), weather.vis_miles);                  
  1698.             #endif
  1699.             #if POLISH
  1700.                 Serial.printf_P( PSTR ("\n[API] [Weather] City             : %s"),weather.city);
  1701.                 Serial.printf_P( PSTR ("\n[API] [Weather] Country          : %s"), weather.country);
  1702.                 Serial.printf_P( PSTR ("\n[API] [Weather] TZ ID            : %s"), weather.tz_id);
  1703.                 Serial.printf_P( PSTR ("\n[API] [Weather] Latitude         : %0.2f"), weather.lat);
  1704.                 Serial.printf_P( PSTR ("\n[API] [Weather] Longitude        : %0.2f"), weather.lon);
  1705.                 Serial.printf_P( PSTR ("\n[API] [Weather] Epoch Time       : %d"), weather.localtime_epoch);
  1706.                 Serial.printf_P( PSTR ("\n[API] [Weather] Localtime        : %s"), weather.localtime);
  1707.                 Serial.printf_P( PSTR ("\n[API] [Weather] Last Updade      : %s"), weather.last_updated);
  1708.                 Serial.printf_P( PSTR ("\n[API] [Weather] Temp C           : %0.2f"), weather.temp_c);
  1709.                 Serial.printf_P( PSTR ("\n[API] [Weather] Temp feel C      : %0.2f"), weather.feelslike_c);
  1710.                 Serial.printf_P( PSTR ("\n[API] [Weather] Temp F           : %0.2f"), weather.temp_f);
  1711.                 Serial.printf_P( PSTR ("\n[API] [Weather] Temp feel F      : %0.2f"), weather.feelslike_f);
  1712.                 Serial.printf_P( PSTR ("\n[API] [Weather] Condition EN     : %s"), weather.condition_en);
  1713.                 Serial.printf_P( PSTR ("\n[API] [Weather] Condition PL     : %s"), weather.condition_pl);
  1714.                 Serial.printf_P( PSTR ("\n[API] [Weather] icon             : %s"), weather.icon);
  1715.                 Serial.printf_P( PSTR ("\n[API] [Weather] icon code        : %d"), weather.code);
  1716.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind speed kph   : %0.2f"), weather.wind_kph);
  1717.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind gust kph    : %0.2f"), weather.gust_kph);
  1718.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind speed mph   : %0.2f"), weather.wind_mph);
  1719.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind gust mph    : %0.2f"), weather.gust_mph);
  1720.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind degree      : %d"), weather.wind_degree);
  1721.                 Serial.printf_P( PSTR ("\n[API] [Weather] Wind dir         : %s"), weather.wind_dir);
  1722.                 Serial.printf_P( PSTR ("\n[API] [Weather] Pressure mb      : %d"), weather.pressure_mb);
  1723.                 Serial.printf_P( PSTR ("\n[API] [Weather] Pressure in      : %0.2f"), weather.pressure_in);
  1724.                 Serial.printf_P( PSTR ("\n[API] [Weather] Precip mm        : %0.2f"), weather.precip_mm);
  1725.                 Serial.printf_P( PSTR ("\n[API] [Weather] Precip in        : %0.2f"), weather.precip_in);
  1726.                 Serial.printf_P( PSTR ("\n[API] [Weather] Humidity         : %d"), weather.humidity);
  1727.                 Serial.printf_P( PSTR ("\n[API] [Weather] Cloud            : %d"), weather.cloud);
  1728.                 Serial.printf_P( PSTR ("\n[API] [Weather] Vis km           : %0.2f"), weather.vis_km);
  1729.                 Serial.printf_P( PSTR ("\n[API] [Weather] Vis miles        : %0.2f"), weather.vis_miles);                  
  1730.             #endif
  1731.             Serial.printf_P( PSTR ("\n+---------------------------------------------------------------------------------------+"));
  1732.         #endif  
  1733.     #endif
  1734.  
  1735.     WeatherUpdate = false;
  1736. }
  1737.  
  1738. /***************************************************************************************************************/
  1739. /*    
  1740.     @definition    httpGETRequest
  1741. */
  1742. /***************************************************************************************************************/
  1743.  
  1744. String httpGETRequest(const char* serverName)
  1745. {
  1746.     WiFiClient client;
  1747.     HTTPClient http;    
  1748.    
  1749.     http.begin(client, serverName);
  1750.     int httpResponseCode = http.GET();
  1751.  
  1752.     String payload = "{}";
  1753.  
  1754.     if (httpResponseCode>0)
  1755.     {
  1756.         #if DEBUG
  1757.             #if SERIAL
  1758.                 #if ENGLISH
  1759.                     Serial.printf_P( PSTR ( "\nHTTP Response code: %d"), httpResponseCode);
  1760.                 #endif
  1761.                 #if POLISH
  1762.                     Serial.printf_P( PSTR ( "\nHTTP Response code: %d"), httpResponseCode);
  1763.                 #endif
  1764.                 #if GERMANY
  1765.                     Serial.printf_P( PSTR ( "\nHTTP Response code: %d"), httpResponseCode);
  1766.                 #endif
  1767.             #endif        
  1768.         #endif
  1769.        
  1770.         payload = http.getString();
  1771.     }
  1772.     else
  1773.     {
  1774.         #if DEBUG
  1775.             #if SERIAL
  1776.                 #if ENGLISH
  1777.                     Serial.printf_P( PSTR ( "\nError code:  %d"), httpResponseCode);
  1778.                 #endif
  1779.                 #if POLISH
  1780.                    Serial.printf_P( PSTR ( "\nError code:  %d"), httpResponseCode);
  1781.                 #endif
  1782.                 #if GERMANY
  1783.                     Serial.printf_P( PSTR ( "\nError code:  %d"), httpResponseCode);
  1784.                 #endif
  1785.             #endif  
  1786.         #endif
  1787.     }
  1788.    
  1789.     http.end();
  1790.  
  1791.     return payload;
  1792. }
  1793.  
  1794. /***************************************************************************************************************/
  1795. /*    
  1796.     @definition    Digit Class
  1797. */
  1798. /***************************************************************************************************************/
  1799.  
  1800.  
  1801. Digit::Digit(PxMATRIX* d, byte value, uint16_t xo, uint16_t yo, uint16_t color)
  1802. {
  1803.     _display = d;
  1804.     _value = value;
  1805.     xOffset = xo;
  1806.     yOffset = yo;
  1807.     _color = color;
  1808. }
  1809.  
  1810. byte Digit::Value()
  1811. {
  1812.     return _value;
  1813. }
  1814.  
  1815. void Digit::drawPixel(uint16_t x, uint16_t y, uint16_t c)
  1816. {
  1817.     _display->drawPixel(xOffset + x, height - (y + yOffset), c);
  1818. }
  1819.  
  1820. void Digit::drawLine(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2, uint16_t c)
  1821. {
  1822.     _display->drawLine(xOffset + x, height - (y + yOffset), xOffset + x2, height - (y2 + yOffset), c);
  1823. }
  1824.  
  1825. void Digit::drawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t c)
  1826. {
  1827.     _display->fillRect(xOffset + x, height - (y + yOffset), w,h, c);
  1828. }
  1829.  
  1830. void Digit::DrawColon(uint16_t c)
  1831. {  
  1832.     drawFillRect(-3, segHeight-1, 2,2, c);
  1833.     drawFillRect(-3, segHeight+1+3, 2,2, c);
  1834. }
  1835.  
  1836. void Digit::drawSeg(byte seg)
  1837. {
  1838.     switch (seg)
  1839.     {
  1840.         case sA: drawLine(1, segHeight * 2 + 2, segWidth, segHeight * 2 + 2, _color); break;
  1841.         case sB: drawLine(segWidth + 1, segHeight * 2 + 1, segWidth + 1, segHeight + 2, _color); break;
  1842.         case sC: drawLine(segWidth + 1, 1, segWidth + 1, segHeight, _color); break;
  1843.         case sD: drawLine(1, 0, segWidth, 0, _color); break;
  1844.         case sE: drawLine(0, 1, 0, segHeight, _color); break;
  1845.         case sF: drawLine(0, segHeight * 2 + 1, 0, segHeight + 2, _color); break;
  1846.         case sG: drawLine(1, segHeight + 1, segWidth, segHeight + 1, _color); break;
  1847.     }
  1848. }
  1849.  
  1850. void Digit::Draw(byte value)
  1851. {
  1852.     byte pattern = digitBits[value];
  1853.     if (bitRead(pattern, 7)) drawSeg(sA);
  1854.     if (bitRead(pattern, 6)) drawSeg(sB);
  1855.     if (bitRead(pattern, 5)) drawSeg(sC);
  1856.     if (bitRead(pattern, 4)) drawSeg(sD);
  1857.     if (bitRead(pattern, 3)) drawSeg(sE);
  1858.     if (bitRead(pattern, 2)) drawSeg(sF);
  1859.     if (bitRead(pattern, 1)) drawSeg(sG);
  1860.     _value = value;
  1861. }
  1862.  
  1863. void Digit::Morph2()
  1864. {
  1865.     for (int i = 0; i <= segWidth; i++)
  1866.     {
  1867.         if (i < segWidth)
  1868.         {
  1869.             drawPixel(segWidth - i, segHeight * 2 + 2, _color);
  1870.             drawPixel(segWidth - i, segHeight + 1, _color);
  1871.             drawPixel(segWidth - i, 0, _color);
  1872.         }
  1873.  
  1874.         drawLine(segWidth + 1 - i, 1, segWidth + 1 - i, segHeight, black);
  1875.         drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1876.         delay(animSpeed);
  1877.     }
  1878. }
  1879.  
  1880. void Digit::Morph3()
  1881. {
  1882.     for (int i = 0; i <= segWidth; i++)
  1883.     {
  1884.         drawLine(0 + i, 1, 0 + i, segHeight, black);
  1885.         drawLine(1 + i, 1, 1 + i, segHeight, _color);
  1886.         delay(animSpeed);
  1887.     }
  1888. }
  1889.  
  1890. void Digit::Morph4()
  1891. {
  1892.     for (int i = 0; i < segWidth; i++)
  1893.     {
  1894.         drawPixel(segWidth - i, segHeight * 2 + 2, black); // Erase A
  1895.         drawPixel(0, segHeight * 2 + 1 - i, _color); // Draw as F
  1896.         drawPixel(1 + i, 0, black); // Erase D
  1897.         delay(animSpeed);
  1898.     }
  1899. }
  1900.  
  1901. void Digit::Morph5()
  1902. {
  1903.     for (int i = 0; i < segWidth; i++)
  1904.     {
  1905.         drawPixel(segWidth + 1, segHeight + 2 + i, black); // Erase B
  1906.         drawPixel(segWidth - i, segHeight * 2 + 2, _color); // Draw as A
  1907.         drawPixel(segWidth - i, 0, _color); // Draw D
  1908.         delay(animSpeed);
  1909.     }
  1910. }
  1911.  
  1912. void Digit::Morph6()
  1913. {
  1914.     for (int i = 0; i <= segWidth; i++)
  1915.     {
  1916.         drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1917.         if (i > 0) drawLine(segWidth - i + 1, 1, segWidth - i + 1, segHeight, black);
  1918.         delay(animSpeed);
  1919.     }
  1920. }
  1921.  
  1922. void Digit::Morph7()
  1923. {
  1924.     for (int i = 0; i <= (segWidth + 1); i++)
  1925.     {
  1926.         drawLine(0 + i - 1, 1, 0 + i - 1, segHeight, black);
  1927.         drawLine(0 + i, 1, 0 + i, segHeight, _color);
  1928.         drawLine(0 + i - 1, segHeight * 2 + 1, 0 + i - 1, segHeight + 2, black);
  1929.         drawLine(0 + i, segHeight * 2 + 1, 0 + i, segHeight + 2, _color);
  1930.         drawPixel(1 + i, 0, black); // D
  1931.         drawPixel(1 + i, segHeight + 1, black); // G
  1932.         delay(animSpeed);
  1933.     }
  1934. }
  1935.  
  1936. void Digit::Morph8()
  1937. {
  1938.     for (int i = 0; i <= segWidth; i++)
  1939.     {
  1940.         drawLine(segWidth - i, segHeight * 2 + 1, segWidth - i, segHeight + 2, _color);
  1941.         if (i > 0) drawLine(segWidth - i + 1, segHeight * 2 + 1, segWidth - i + 1, segHeight + 2, black);
  1942.  
  1943.         drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1944.         if (i > 0) drawLine(segWidth - i + 1, 1, segWidth - i + 1, segHeight, black);
  1945.  
  1946.         if (i < segWidth)
  1947.         {
  1948.             drawPixel(segWidth - i, 0, _color); // D
  1949.             drawPixel(segWidth - i, segHeight + 1, _color); // G
  1950.         }
  1951.         delay(animSpeed);
  1952.     }
  1953. }
  1954.  
  1955. void Digit::Morph9()
  1956. {
  1957.     for (int i = 0; i <= (segWidth + 1); i++)
  1958.     {
  1959.         drawLine(0 + i - 1, 1, 0 + i - 1, segHeight, black);
  1960.         drawLine(0 + i, 1, 0 + i, segHeight, _color);
  1961.         delay(animSpeed);
  1962.     }
  1963. }
  1964.  
  1965. void Digit::Morph0()
  1966. {
  1967.     for (int i = 0; i <= segWidth; i++)
  1968.     {
  1969.         if (_value==1)
  1970.         {
  1971.             drawLine(segWidth - i, segHeight * 2+1 , segWidth - i, segHeight + 2, _color);
  1972.             if (i > 0) drawLine(segWidth - i + 1, segHeight * 2+1, segWidth - i + 1, segHeight + 2, black);
  1973.             drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1974.             if (i > 0) drawLine(segWidth - i + 1, 1, segWidth - i + 1, segHeight, black);
  1975.             if (i<segWidth) drawPixel(segWidth - i, segHeight * 2 + 2 , _color); // Draw A
  1976.             if (i<segWidth) drawPixel(segWidth - i, 0, _color); // Draw D
  1977.         }
  1978.    
  1979.         if (_value==2)
  1980.         {
  1981.             drawLine(segWidth - i, segHeight * 2+1 , segWidth - i, segHeight + 2, _color);
  1982.             if (i > 0) drawLine(segWidth - i + 1, segHeight * 2+1, segWidth - i + 1, segHeight + 2, black);
  1983.             drawPixel(1+i, segHeight + 1, black); // Erase G left to right
  1984.             if (i<segWidth) drawPixel(segWidth + 1, segHeight + 1- i, _color);// Draw C
  1985.         }
  1986.  
  1987.         if (_value==3)
  1988.         {
  1989.             drawLine(segWidth - i, segHeight * 2+1 , segWidth - i, segHeight + 2, _color);
  1990.             if (i > 0) drawLine(segWidth - i + 1, segHeight * 2+1, segWidth - i + 1, segHeight + 2, black);
  1991.             drawLine(segWidth - i, 1, segWidth - i, segHeight, _color);
  1992.             if (i > 0) drawLine(segWidth - i + 1, 1, segWidth - i + 1, segHeight, black);
  1993.             drawPixel(segWidth - i, segHeight + 1, black); // G
  1994.          }
  1995.    
  1996.         if (_value==5)
  1997.         {
  1998.             if (i<segWidth)
  1999.             {
  2000.                 if (i>0) drawLine(1 + i, segHeight * 2 + 1, 1 + i, segHeight + 2, black);
  2001.                 drawLine(2 + i, segHeight * 2 + 1, 2 + i, segHeight + 2, _color);
  2002.             }
  2003.         }
  2004.    
  2005.         if (_value==5 || _value==9)
  2006.         {
  2007.               if (i<segWidth) drawPixel(segWidth - i, segHeight + 1, black);
  2008.               if (i<segWidth) drawPixel(0, segHeight - i, _color);
  2009.         }
  2010.         delay(animSpeed);
  2011.     }
  2012. }
  2013.  
  2014. void Digit::Morph1()
  2015. {
  2016.     for (int i = 0; i <= (segWidth + 1); i++)
  2017.     {
  2018.         drawLine(0 + i - 1, 1, 0 + i - 1, segHeight, black);
  2019.         drawLine(0 + i, 1, 0 + i, segHeight, _color);
  2020.         drawLine(0 + i - 1, segHeight * 2 + 1, 0 + i - 1, segHeight + 2, black);
  2021.         drawLine(0 + i, segHeight * 2 + 1, 0 + i, segHeight + 2, _color);
  2022.         drawPixel(1 + i, segHeight * 2 + 2, black); // A
  2023.         drawPixel(1 + i, 0, black); // D
  2024.         drawPixel(1 + i, segHeight + 1, black); // G
  2025.         delay(animSpeed);
  2026.     }
  2027. }
  2028.  
  2029. void Digit::Morph(byte newValue)
  2030. {
  2031.     switch (newValue)
  2032.     {
  2033.         case 2: Morph2(); break;
  2034.         case 3: Morph3(); break;
  2035.         case 4: Morph4(); break;
  2036.         case 5: Morph5(); break;
  2037.         case 6: Morph6(); break;
  2038.         case 7: Morph7(); break;
  2039.         case 8: Morph8(); break;
  2040.         case 9: Morph9(); break;
  2041.         case 0: Morph0(); break;
  2042.         case 1: Morph1(); break;
  2043.     }
  2044.     _value = newValue;
  2045. }
Advertisement
Add Comment
Please, Sign In to add comment