PowerTGS440

TFT_CLOCK_DHT_AM2320_SENSOR_v2.3

Jun 23rd, 2021
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 54.64 KB | None | 0 0
  1. // ------------------------------------------------------------------------------------------------------------------- //
  2. //                                                                                                                     //
  3. // Simple ESP8266 NodeMCU 2.3 SimpleTFT Clock & DHT11 & AM2320 by TOMASZ MAJCHER (TRANSLINE GROUP POAND)               //
  4. //                                                                                                                     //
  5. // e-mail  : [email protected]                                                                               //
  6. // licence : DonationWare                                                                                              //
  7. // paypal  : @TomaszMajcher                                                                                            //
  8. // www     : https://esp32dev.blogspot.com/                                                                            //
  9. //                                                                                                                     //
  10. // ------------------------------------------------------------------------------------------------------------------- //
  11. //
  12. // v1.0 Base  (13.06.2021) by Tomasz Majcher (tools & base)
  13. // v2.3 Beta  (23.06.2021) by Tomasz Majcher (clock, date, DHT11, AM2320) Free Full-Beta Version
  14. //
  15. // ------------------------------------------------------------------------------------------------------------------- //
  16. //
  17. // ILI9341 Driver (Pinout) Hardware SPI !!!
  18. //
  19. // VCC to         :   3.3V
  20. // GND to         :   GND
  21. // CS pin to      :   D3
  22. // Reset pin to   :   Reset
  23. // DC pin to      :   D4
  24. // SDI pin to     :   D7
  25. // SCK pin to     :   D5
  26. //
  27. //
  28. //  AM2320 Driver (Pinout) SCA/SDL
  29. //
  30. //  VCC to        :   3.3V
  31. //  GND to        :   GND
  32. //  SCL to        :   D1 (ESP8266)
  33. //  SDA to        :   D2 (ESP8266)
  34. //
  35. //
  36. //  DHT11 Driver (Pinout)
  37. //
  38. //  VCC to        :   3.3V
  39. //  GND to        :   GND
  40. //  DATA to       :   D0
  41. //
  42. //
  43. //
  44. //
  45. // (23.06.2021) v2.4 beta  -  update : add multilanguage (on TFT)
  46. // (23.06.2021) v2.3 beta  -  update : add switch (dat/evening/night) mode
  47. // (23.06.2021) v2.2 beta  -  update : add Night Mode (stars)
  48. // (23.06.2021) v2.1 beta  -  update : add Evening Mode Color
  49. // (22.06.2021) v2.0 final -  official free final version !!!
  50. // (22.06.2021) v1.9 beta  -  update : add TFT_ShowTemperature & TFT_ShowHumidity (DHT11) outside ROOM
  51. // (22.06.2021) v1.8 beta  -  update : add DHT11 sensor (temperature & humidity) outside ROOM
  52. // (21.06.2021) v1.7 beta  -  update : add TFT_ShowTemperature & TFT_ShowHumidity (AM2320) inside ROOM
  53. // (21.06.2021) v1.6 beta  -  update : add AM2320 sensor (temperature & humudity) inside ROOM
  54. // (20.06.2021) v1.5 beta  -  update : add TFT_ShowProgres (show progres bar for second)
  55. // (20.06.2021) v1.4 beta  -  update : add TFT_ShowBug (show flying bug)
  56. // (20.06.2021) v1.3 beta  -  update : add TFT_ShowDate (show date on TFT display) from Task3 (one per min)
  57. // (20.06.2021) v1.2 beta  -  update : add TFT_ShowTime (show time on TFT display) from Task0 (one per sec)
  58. // (20.06.2021) v1.1 beta  -  update : add TFT (test, setup library -> ILI9341, pinout)
  59. //
  60. // ------------------------------------------------------------------------------------------------------------------- //
  61. // --- I N C L U D E   L I B R A R Y --------------------------------------------------------------------------------- //
  62. // ------------------------------------------------------------------------------------------------------------------- //
  63.  
  64. extern "C" char* sbrk(int incr);
  65.  
  66. #include <ESP8266WiFi.h>                                         // biblioteka Wi-Fi
  67. #include <NTPClient.h>                                           // NTP klient (Time)
  68. #include <WiFiUdp.h>                                             // UDP dla NTP (Time)
  69. #include <TaskScheduler.h>                                       // scheluder
  70. #include <TimeLib.h>
  71. #include <Arduino.h>
  72.  
  73. // --- AM2320 Temperature & Humidity Sensor -------------------------------------------------------------------------- //
  74.  
  75. #include <Adafruit_Sensor.h>                                     //AM2320 sensor library
  76. #include <Adafruit_AM2320.h>                                     //AM2320 sensor library
  77.  
  78. Adafruit_AM2320 AM2320 = Adafruit_AM2320();                      // create object
  79.  
  80. // --- DHT11 Temperature & Humidity Sensor --------------------------------------------------------------------------- //
  81.  
  82. #include "DHTesp.h"                                              // library
  83. #define DHTpin D0                                                // define PIN
  84.  
  85. DHTesp dht;                                                      // create object
  86.  
  87. // ------------------------------------------------------------------------------------------------------------------- //
  88. // --- L A N G U A G E   S E T U P ----------------------------------------------------------------------------------- //
  89. // ------------------------------------------------------------------------------------------------------------------- //
  90.  
  91. #define LANGUAGE 0                                            // 0 (Polish), 1 (English), 2 (Germany)
  92.                                                              
  93. #if LANGUAGE == 0                                                
  94.     #define POLISH 1
  95.     #define ENGLISH 0
  96.     #define GERMANY 0                                          
  97. #endif
  98.  
  99. #if LANGUAGE == 1                                                      
  100.     #define POLISH 0                                        
  101.     #define ENGLISH 1
  102.     #define GERMANY 0
  103. #endif
  104.  
  105. #if LANGUAGE == 2
  106.     #define POLISH 0
  107.     #define ENGLISH 0
  108.     #define GERMANY 1
  109. #endif      
  110.  
  111. // ------------------------------------------------------------------------------------------------------------------- //
  112. // --- M A C R O   D E F I N E --------------------------------------------------------------------------------------- //
  113. // ------------------------------------------------------------------------------------------------------------------- //
  114.  
  115. #define ARRAY_SIZE(a)   (sizeof(a) / sizeof((a)[0]))
  116.  
  117. // ------------------------------------------------------------------------------------------------------------------- //
  118. // --- N E T W O R K   S E T T I N G S ------------------------------------------------------------------------------- //
  119. // ------------------------------------------------------------------------------------------------------------------- //
  120.  
  121. const char *ssid     = "your_ssid";                                  // network wifi ssid  
  122. const char *password = "your_pass";                                  // network wifi password
  123.  
  124. // ------------------------------------------------------------------------------------------------------------------- //
  125. // --- T F T --------------------------------------------------------------------------------------------------------- //
  126. // ------------------------------------------------------------------------------------------------------------------- //
  127.  
  128. //#include "Free_Fonts.h"
  129. #include "SPI.h"
  130. #include "TFT_eSPI.h"
  131.  
  132. TFT_eSPI tft = TFT_eSPI();
  133.  
  134. // define color
  135.  
  136. #define TFT_LIGHTGRAY         tft.color565(163, 159, 158)
  137. #define TFT_SWEETBLUE         tft.color565(0, 128, 255)
  138.  
  139. // define day mode color
  140.  
  141. #define TFT_DAY_TEXT          TFT_BLACK
  142. #define TFT_DAY_BACKGROUND    TFT_LIGHTGRAY
  143.  
  144. // define night mode color
  145.  
  146. #define TFT_NIGHT_TEXT        TFT_LIGHTGRAY
  147. #define TFT_NIGHT_BACKGROUND  TFT_BLACK
  148.  
  149. // tft mode
  150.  
  151. bool day_mode = true;                        // tryb dzienny
  152. bool evening_mode = false;                   // tryb wieczorny
  153. bool night_mode = false;                     // tryb nocny
  154. bool change_mode = false;                    // flag mode
  155.  
  156. int TFT_MODE_COLOR = TFT_BLACK;               // start default color
  157. int TFT_MODE_BACKGROUND = TFT_LIGHTGRAY;      // start default color
  158.  
  159. //int TFT_MODE_COLOR = TFT_LIGHTGRAY;               // start default color
  160. //int TFT_MODE_BACKGROUND = TFT_BLACK;      // start default color
  161.  
  162. // define cords
  163.  
  164. #define x_min 0
  165. #define y_min 0
  166. #define x_max 320
  167. #define y_max 240
  168. #define frame 5
  169.  
  170. // ------------------------------------------------------------------------------------------------------------------- //
  171. // --- S E R I A L   S E T T I N G S --------------------------------------------------------------------------------- //
  172. // ------------------------------------------------------------------------------------------------------------------- //
  173.  
  174. #define SERIAL true
  175. #define SerialSpeed 57600
  176.  
  177. // ------------------------------------------------------------------------------------------------------------------- //
  178. // --- P R O T O T Y P E --------------------------------------------------------------------------------------------- //
  179. // ------------------------------------------------------------------------------------------------------------------- //
  180.  
  181. void scheluderInit();                 // run from setup() - init scheluder
  182. void statWiFi();                      // show Wi-Fi Status
  183. void initWiFi();                      // init Wi-Fi connection
  184.  
  185. void TFT_Init();                      // init TFT (from setup)
  186. void TFT_ShowDate();                  // show Date on TFT
  187. void TFT_ShowTime();                  // show Time on TFT
  188. void TFT_ShowBug();                   // show BUG on TFT
  189. void TFT_ShowHumidity();              // show Humidity (inside / outside) from sensor AM2320 / DHT11
  190. void TFR_ShowTemperature();           // show Temperature (inside / outside) from sensor AM2320 / DHT11
  191. void TFT_ShowStars();                 // show stars and time on NIGHT (night_mode)
  192. void TFT_ShowProgres();               // show progres bar for second
  193.  
  194. // ------------------------------------------------------------------------------------------------------------------- //
  195. // --- P R O T O T Y P E --- C O R E T A S K ------------------------------------------------------------------------- //
  196. // ------------------------------------------------------------------------------------------------------------------- //
  197.  
  198. void Task0Callback();                 // function Task0 for ESP8266 Core
  199. void Task1Callback();                 // function Task1 for ESP8266 Core
  200. void Task2Callback();                 // function Task2 for ESP8266 Core
  201. void Task3Callback();                 // function Task3 for ESP8266 Core
  202. void Task4Callback();                 // function Task4 for ESP8266 Core
  203. void Task5Callback();                 // function Task4 for ESP8266 Core
  204. void Task6Callback();                 // function Task4 for ESP8266 Core
  205.  
  206. #define Micros_01         50          // 1/100 sekundy
  207. #define Second_01       1000          // 01 second timeout makro definition
  208. #define Second_05       5000          // 05 second timeout makro definition
  209. #define Second_10       10000         // 10 second timeout makro definition
  210. #define Second_30       30000         // 30 second timeout makro definition
  211. #define Second_60       60000         // 60 second timeout makro definition
  212. #define Minute_01       60000         // 01 minute timeout makro definition
  213. #define Minute_05      300000         // 05 minute timeout makro definition
  214. #define Minute_10      600000         // 10 minute timeout makro definition
  215. #define Minute_30     1800000         // 30 minute timeout makro definiction
  216. #define Minute_60     3600000         // 30 minute timeout makro definiction
  217.  
  218.  
  219. // ------------------------------------------------------------------------------------------------------------------- //
  220. // --- Z A D A N I A   S C H E L U D E R ' A ------------------------------------------------------------------------- //
  221. // ------------------------------------------------------------------------------------------------------------------- //
  222.                                                                                                    
  223. Task task_0( Second_01,  TASK_FOREVER, &Task0Callback);         // task_0 run at interval Second_01            
  224. Task task_1( Second_60,  TASK_FOREVER, &Task1Callback);         // task_1 run at interval Second_60            
  225. Task task_2( Second_01,  TASK_FOREVER, &Task2Callback);         // task_2 run at interval Second_10            
  226. Task task_3( Minute_01,  TASK_FOREVER, &Task3Callback);         // task_3 run at interval Minute_01  
  227. Task task_4( Minute_10,  TASK_FOREVER, &Task4Callback);         // task_4 run at interval Minute_10  
  228. Task task_5( Micros_01,  TASK_FOREVER, &Task5Callback);         // task_4 run at interval 1/10 sec
  229. Task task_6( Minute_60,  TASK_FOREVER, &Task6Callback);         // task_4 run at interval Minute_60  
  230.                                                                                                    
  231. Scheduler runner;    
  232.  
  233. // ------------------------------------------------------------------------------------------------------------------- //
  234. //                                              *** WiFi Reconect ***                                                  //
  235. // ------------------------------------------------------------------------------------------------------------------- //
  236.  
  237. unsigned long previousMillis = 0;
  238. unsigned long interval = 30000;
  239.  
  240. // ------------------------------------------------------------------------------------------------------------------- //
  241. //                                              *** STRUKTURA Time ***                                                 //
  242. // ------------------------------------------------------------------------------------------------------------------- //
  243.  
  244. struct TIME_DATA
  245. {
  246.     int     Hour = 0;
  247.     int     Minute  = 0;
  248.     int     Second = 0;
  249.     String  FormatedData  = "NULL";
  250.     String  ShortData = "NULL";
  251.     String  LongData = "NULL";
  252.     String  TFT_Data = "NULL";
  253.     String  TFT_Time = "NULL";
  254.     int     DayOfTheWeek = 0;
  255.     int     DayOfTheMonth = 0;
  256.     int     Month = 0;
  257.     int     Year = 0;
  258. }
  259. Time;
  260.  
  261.  
  262. // ------------------------------------------------------------------------------------------------------------------- //
  263. //                                              *** STRUKTURA AM2320 ***                                               //
  264. // ------------------------------------------------------------------------------------------------------------------- //
  265.  
  266. struct AM2320Sensor
  267. {
  268.     float temperature   = 0;
  269.     float humidity      = 0;
  270. }
  271. sensor;
  272.  
  273. // ------------------------------------------------------------------------------------------------------------------- //
  274. //                                              *** STRUKTURA DHT11 ***                                                //
  275. // ------------------------------------------------------------------------------------------------------------------- //
  276.  
  277.  
  278. struct MyDHT
  279. {
  280.     float temperature = 22.12;   // default - DHT11/DHT22 sample start value
  281.     float humidity    = 84.05;   // default - DHT11/DHT22 sample start value
  282. }
  283. myDHT;
  284.  
  285. // ------------------------------------------------------------------------------------------------------------------- //
  286. //                                                    *** S T A R S ***                                                //
  287. // ------------------------------------------------------------------------------------------------------------------- //
  288.  
  289. #define NSTARS 1024
  290.  
  291. uint8_t sx[NSTARS] = {};
  292. uint8_t sy[NSTARS] = {};
  293. uint8_t sz[NSTARS] = {};
  294.  
  295. uint8_t za, zb, zc, zx;
  296.  
  297. uint8_t __attribute__((always_inline)) rng()
  298. {
  299.     zx++;
  300.     za = (za^zc^zx);
  301.     zb = (zb+za);
  302.     zc = ((zc+(zb>>1))^za);
  303.     return zc;
  304. }
  305.  
  306.  
  307. // ------------------------------------------------------------------------------------------------------------------- //
  308. //                                              *** STRUKTURA DZIEN ***                                                //
  309. // ------------------------------------------------------------------------------------------------------------------- //
  310.  
  311. #if POLISH
  312.     const char Day_0 [] = "Niedziela";
  313.     const char Day_1 [] = "Poniedzialek";
  314.     const char Day_2 [] = "Wtorek";
  315.     const char Day_3 [] = "Sroda";
  316.     const char Day_4 [] = "Czwartek";
  317.     const char Day_5 [] = "Piatek";
  318.     const char Day_6 [] = "Sobota";
  319. #endif
  320.  
  321. #if ENGLISH
  322.     const char Day_0 [] = "Sunday";
  323.     const char Day_1 [] = "Monday";
  324.     const char Day_2 [] = "Tuesday";
  325.     const char Day_3 [] = "Wednesday";
  326.     const char Day_4 [] = "Thursday";
  327.     const char Day_5 [] = "Friday";
  328.     const char Day_6 [] = "Saturday";
  329. #endif
  330.  
  331. #if GERMANY
  332.     const char Day_0 [] = "Sonntag";
  333.     const char Day_1 [] = "Montag";
  334.     const char Day_2 [] = "Dienstag";
  335.     const char Day_3 [] = "Mittwoch";
  336.     const char Day_4 [] = "Donnerstag";
  337.     const char Day_5 [] = "Freitag";
  338.     const char Day_6 [] = "Samstag";
  339. #endif
  340.  
  341. const char * const DAY[] = { Day_0, Day_1, Day_2, Day_3, Day_4, Day_5, Day_6 }; // dni tygodnia [0..6]
  342.  
  343. // ------------------------------------------------------------------------------------------------------------------- //
  344. //                                              *** STRUKTURA MONTH ***                                                //
  345. // ------------------------------------------------------------------------------------------------------------------- //
  346.  
  347. #if POLISH
  348.     const char MONTH_0  [] = "NULL";
  349.     const char MONTH_1  [] = "Styczen";
  350.     const char MONTH_2  [] = "Luty";
  351.     const char MONTH_3  [] = "Marzec";
  352.     const char MONTH_4  [] = "Kwiecien";
  353.     const char MONTH_5  [] = "Maj";
  354.     const char MONTH_6  [] = "Czerwiec";
  355.     const char MONTH_7  [] = "Lipiec";
  356.     const char MONTH_8  [] = "Sierpien";
  357.     const char MONTH_9  [] = "Wrzesien";
  358.     const char MONTH_10 [] = "Pazdziernik";
  359.     const char MONTH_11 [] = "Listopad";
  360.     const char MONTH_12 [] = "Grudzien";
  361. #endif
  362.  
  363. #if ENGLISH
  364.     const char MONTH_0  [] = "NULL";
  365.     const char MONTH_1  [] = "January";
  366.     const char MONTH_2  [] = "February";
  367.     const char MONTH_3  [] = "March";
  368.     const char MONTH_4  [] = "April";
  369.     const char MONTH_5  [] = "May";
  370.     const char MONTH_6  [] = "June";
  371.     const char MONTH_7  [] = "July";
  372.     const char MONTH_8  [] = "August";
  373.     const char MONTH_9  [] = "September";
  374.     const char MONTH_10 [] = "October";
  375.     const char MONTH_11 [] = "November";
  376.     const char MONTH_12 [] = "December";
  377. #endif
  378.  
  379. #if GERMANY
  380.     const char MONTH_0  [] = "NULL";
  381.     const char MONTH_1  [] = "Januar";
  382.     const char MONTH_2  [] = "Februar";
  383.     const char MONTH_3  [] = "März";
  384.     const char MONTH_4  [] = "April";
  385.     const char MONTH_5  [] = "Mai";
  386.     const char MONTH_6  [] = "Juni";
  387.     const char MONTH_7  [] = "Juli";
  388.     const char MONTH_8  [] = "August";
  389.     const char MONTH_9  [] = "September";
  390.     const char MONTH_10 [] = "Oktober";
  391.     const char MONTH_11 [] = "November";
  392.     const char MONTH_12 [] = "Dezember";
  393. #endif
  394.    
  395.     const char * const MONTH[] = { MONTH_0, MONTH_1, MONTH_2, MONTH_3, MONTH_4, MONTH_5, MONTH_6,
  396.                                    MONTH_7, MONTH_8, MONTH_9, MONTH_10, MONTH_11, MONTH_12 };
  397.  
  398. // ------------------------------------------------------------------------------------------------------------------- //
  399. // --- T O O L S   C L A S S ----------------------------------------------------------------------------------------- //
  400. // ------------------------------------------------------------------------------------------------------------------- //  
  401.  
  402. class TOOLS
  403. {
  404.     private:
  405.  
  406.     public:
  407.       void TypeWriter(const String & message, unsigned int wait, bool lf = true);
  408.       void FreeRam(bool lf = true);
  409.       void CpuInfo(bool lf = true);
  410.       void WiFiInfo(bool lf = true);      
  411.       inline void BreakLine();
  412.       inline void PrintLine(byte lenght = 60);
  413. };
  414.  
  415. // ------------------------------------------------------------------------------------------------------------------- //  
  416.  
  417. void TOOLS :: TypeWriter(const String & message, unsigned int wait, bool lf)
  418. {
  419.     if(lf) Serial.printf("\n");   // if lf is true print next line
  420.    
  421.     for(const char c : message)
  422.     {
  423.         Serial.print(c);    
  424.         delay(wait);  
  425.     }  
  426. }
  427.  
  428. // ------------------------------------------------------------------------------------------------------------------- //
  429.  
  430. void TOOLS :: FreeRam(bool lf)
  431. {
  432.     if(lf) Serial.printf("\n");   // if lf is true print next line
  433.  
  434.     Serial.printf("[TOOLS] [Memory Free] \t\t: %u [kB]", ESP.getFreeHeap());      
  435. }
  436.  
  437. // ------------------------------------------------------------------------------------------------------------------- //
  438.  
  439. void TOOLS :: CpuInfo(bool lf)
  440. {
  441.     if(lf) Serial.printf("\n");   // if lf is true print next line
  442.  
  443.     Serial.printf("[TOOLS] [CPU frequency] \t: %u [MHz]",ESP.getCpuFreqMHz());      
  444. }
  445.  
  446. // ------------------------------------------------------------------------------------------------------------------- //
  447.  
  448. void TOOLS :: WiFiInfo(bool lf)
  449. {
  450.     if(lf) Serial.printf("\n");   // if lf is true print next line
  451.    
  452.     Serial.printf("[TOOLS] [IP adress] \t\t: %s", WiFi.localIP().toString().c_str());
  453. }
  454.  
  455. // ------------------------------------------------------------------------------------------------------------------- //
  456.  
  457. inline void TOOLS :: BreakLine()
  458. {
  459.     Serial.printf("\n");   // if lf is true print next line
  460. }
  461.  
  462. // ------------------------------------------------------------------------------------------------------------------- //
  463.  
  464. inline void TOOLS :: PrintLine(byte lenght)
  465. {
  466.     for(byte i = 0; i <= lenght; i++) Serial.print("-");
  467. }
  468.  
  469. // ------------------------------------------------------------------------------------------------------------------- //
  470. // --- O B J E C T   I N I T ----------------------------------------------------------------------------------------- //
  471. // ------------------------------------------------------------------------------------------------------------------- //  
  472.  
  473. WiFiUDP ntpUDP;                                                
  474. NTPClient timeClient(ntpUDP, "pool.ntp.org", 3600);  
  475. TOOLS tools;
  476.  
  477. // ------------------------------------------------------------------------------------------------------------------- //
  478. // --- Task0Callback() ----------------------------------------------------------------------------------------------- //
  479. // ------------------------------------------------------------------------------------------------------------------- //
  480.  
  481. void Task0Callback()
  482. {
  483.     String bufor = "NULL";
  484.  
  485.     static bool STEP = false;
  486.  
  487.     if (Time.Hour < 10)
  488.     {
  489.         bufor =  "0";
  490.         bufor += String(Time.Hour);
  491.     }
  492.     else
  493.     {
  494.         bufor = String(Time.Hour);
  495.     }
  496.  
  497.     if (STEP)                           // step 0 sec show :
  498.     {
  499.         bufor += ":";
  500.         STEP = false;
  501.     }
  502.     else                                // step 1 sec show _
  503.     {
  504.         bufor += " ";
  505.         STEP = true;
  506.     }
  507.  
  508.     if (Time.Minute < 10)
  509.     {
  510.         bufor +=  "0";
  511.         bufor += String(Time.Minute);
  512.     }
  513.     else
  514.     {
  515.         bufor += String(Time.Minute);
  516.     }
  517.  
  518.     Time.TFT_Time = bufor;                        // copy bufor to TFT_Time
  519.  
  520.     if (!night_mode) TFT_ShowTime();                   // show time on TFT  
  521.  
  522. }
  523.  
  524. // ------------------------------------------------------------------------------------------------------------------- //
  525. // --- Task1Callback() ----------------------------------------------------------------------------------------------- //
  526. // ------------------------------------------------------------------------------------------------------------------- //
  527.  
  528. void Task1Callback()
  529. {
  530.     // -------------------------------------------------------------------------------------------- //
  531.     // --- temperature & humidity (INSIDE) from AM2320 sensor ------------------------------------- //
  532.     // -------------------------------------------------------------------------------------------- //
  533.    
  534.     sensor.temperature = AM2320.readTemperature();      // get temperature from AM2320 sensor
  535.     sensor.humidity    = AM2320.readHumidity();         // get humidity from AM2320 sensor    
  536.  
  537.     if (!night_mode) TFT_ShowTemperature();                   // show temperature IN/OUT on TFT
  538.     if (!night_mode) TFT_ShowHumidity();                      // show humidity IN/OUT on TFT
  539.  
  540.     // -------------------------------------------------------------------------------------------- //
  541.     // --- temperature & humidiry (OUTSIDE) from DHT11 sensor ------------------------------------- //
  542.     // -------------------------------------------------------------------------------------------- //
  543.  
  544.     TempAndHumidity sensor = dht.getTempAndHumidity();    
  545.  
  546.     myDHT.temperature = sensor.temperature;
  547.     myDHT.humidity  = sensor.humidity;
  548.  
  549.     // -------------------------------------------------------------------------------------------- //
  550.  
  551.     #if SERIAL
  552.        
  553.         String bufor;
  554.        
  555.         if (Time.Hour < 10)
  556.         {
  557.             bufor =  "0";
  558.             bufor += String(Time.Hour);
  559.         }
  560.         else
  561.         {
  562.             bufor = String(Time.Hour);
  563.         }
  564.  
  565.         bufor += ":";
  566.  
  567.         if (Time.Minute < 10)
  568.         {
  569.             bufor +=  "0";
  570.             bufor += String(Time.Minute);
  571.         }
  572.         else
  573.         {
  574.             bufor += String(Time.Minute);
  575.         }
  576.  
  577.         if (Time.Hour < 12) bufor += " AM";
  578.         else                bufor += " PM";
  579.        
  580.         Serial.printf("\n\n[ESP] [TASK1] [Time NTP] \t: %s", bufor.c_str());
  581.         Serial.printf("\n[ESP] [TASK1] [LongData]  \t: %s ", Time.LongData.c_str());
  582.         Serial.printf("\n[ESP] [TASK1] [ShortData] \t: %s ", Time.ShortData.c_str());
  583.  
  584.         #if POLISH
  585.             Serial.printf("\n\n[ESP] [TASK1] [Temperatura] \t: %2.2f stopni C",sensor.temperature);
  586.             Serial.printf("\n[ESP] [TASK1] [Wilgotnosc] \t: %2.2f %%RH",sensor.humidity);
  587.         #endif
  588.         #if GERMANY
  589.             Serial.printf("\n\n[ESP] [TASK1] [Temperature] \t: %2.2f Grad C",sensor.temperature);
  590.             Serial.printf("\n[ESP] [TASK1] [Feuchtigkeit] \t: %2.2f %%RH",sensor.humidity);
  591.         #endif
  592.         #if ENGLISH
  593.             Serial.printf("\n\n[ESP] [TASK1] [Temperature] \t: %2.2f degrees C",sensor.temperature);
  594.             Serial.printf("\n[ESP] [TASK1] [Humidity] \t: %2.2f %%RH",sensor.humidity);
  595.         #endif
  596.        
  597.     #endif            
  598. }
  599.  
  600. // ------------------------------------------------------------------------------------------------------------------- //
  601. // --- Task2Callback() ----------------------------------------------------------------------------------------------- //
  602. // ------------------------------------------------------------------------------------------------------------------- //
  603.  
  604. void Task2Callback()
  605. {
  606.     timeClient.update();                                 // time update                                                        
  607.                                                                                    
  608.     Time.Hour    =  timeClient.getHours()+1;             // zapisz godzinę z serwera
  609.     Time.Minute  =  timeClient.getMinutes();             // zapisz minutę z serwera
  610.     Time.Second  =  timeClient.getSeconds();             // zapisz sekundę z serwera
  611.    
  612.     if (!night_mode) TFT_ShowProgres();
  613. }
  614.  
  615. // ------------------------------------------------------------------------------------------------------------------- //
  616. // --- Task3Callback() ----------------------------------------------------------------------------------------------- //
  617. // ------------------------------------------------------------------------------------------------------------------- //
  618.  
  619. void Task3Callback()
  620. {
  621.     tools.BreakLine();                                   // breaking line
  622.     tools.FreeRam();                                     // show Free RAM
  623.     tools.CpuInfo();                                     // Show CPU
  624.     tools.WiFiInfo();                                    // Show WiFi Adress
  625.  
  626.     if (!night_mode) TFT_ShowDate();                           // Show Date on TFT
  627. }
  628.  
  629. // ------------------------------------------------------------------------------------------------------------------- //
  630. // --- Task4Callback() ----------------------------------------------------------------------------------------------- //
  631. // ------------------------------------------------------------------------------------------------------------------- //
  632.  
  633. void Task4Callback()
  634. {
  635.     // ------------------------------------------------------------------------------------- //
  636.  
  637.     if(day_mode && Time.Hour >= 16)                           // change color to evening mode
  638.     {
  639.         day_mode = false;
  640.         evening_mode = true;
  641.         change_mode = true;
  642.     }
  643.     else
  644.     if(evening_mode && Time.Hour >= 19)                       // change color to night mode
  645.     {
  646.         evening_mode = false;
  647.         night_mode = true;
  648.         change_mode = true;
  649.     }
  650.     else
  651.     if(night_mode && Time.Hour >= 7 && Time.Hour < 20)        // change color to day mode
  652.     {
  653.         night_mode = false;
  654.         day_mode = true;
  655.         change_mode = true;
  656.     }
  657.  
  658.     // ------------------------------------------------------------------------------------ //
  659.    
  660.     if(day_mode)
  661.     {
  662.         TFT_MODE_COLOR        = TFT_DAY_TEXT;
  663.         TFT_MODE_BACKGROUND   = TFT_DAY_BACKGROUND;
  664.     }
  665.     else
  666.     if(evening_mode)
  667.     {
  668.         TFT_MODE_COLOR        = TFT_NIGHT_TEXT;
  669.         TFT_MODE_BACKGROUND   = TFT_NIGHT_BACKGROUND;
  670.     }
  671.     else
  672.     if(night_mode)
  673.     {
  674.         TFT_MODE_COLOR        = TFT_NIGHT_TEXT;
  675.         TFT_MODE_BACKGROUND   = TFT_NIGHT_BACKGROUND;
  676.     }
  677.  
  678.     // ------------------------------------------------------------------------------------ //
  679.  
  680.     if(change_mode && !night_mode)
  681.     {
  682.         TFT_DrawPanel();
  683.         TFT_ShowBug();
  684.         TFT_ShowDate();                  // show Date on TFT
  685.         TFT_ShowTime();                  // show Time on TFT
  686.         TFT_ShowHumidity();              // show Humidity (inside / outside) from sensor AM2320 / DHT11
  687.         TFT_ShowTemperature();           // show Temperature (inside / outside) from sensor AM2320 / DHT11
  688.         TFT_ShowProgres();
  689.         change_mode = false;
  690.     }
  691.     else
  692.     if(change_mode && night_mode)
  693.     {
  694.         change_mode = false;    
  695.     }
  696. }
  697.  
  698. // ------------------------------------------------------------------------------------------------------------------- //
  699. // --- Task3Callback() ----------------------------------------------------------------------------------------------- //
  700. // ------------------------------------------------------------------------------------------------------------------- //
  701.  
  702. void Task5Callback()
  703. {
  704.     if (!night_mode) TFT_ShowBug();          // pokaż robala
  705. }
  706. // ------------------------------------------------------------------------------------------------------------------- //
  707. // --- Task6Callback() ----------------------------------------------------------------------------------------------- //
  708. // ------------------------------------------------------------------------------------------------------------------- //
  709.  
  710. void Task6Callback()
  711. {
  712.     timeClient.update();                                                                              
  713.    
  714.     unsigned long epochTime = timeClient.getEpochTime();                                              
  715.     struct tm *ptm = gmtime ( (time_t *) &epochTime );                                          
  716.                                                                                                
  717.     Time.DayOfTheWeek      =   timeClient.getDay();                                          
  718.     Time.DayOfTheMonth     =   ptm->tm_mday;                                                
  719.     Time.Month             =   ptm->tm_mon+1;                                                
  720.     Time.Year              =   ptm->tm_year+1900;
  721.  
  722.     Time.FormatedData   =   String(DAY[Time.DayOfTheWeek])
  723.                         +   ", "
  724.                         +   String(Time.DayOfTheMonth)
  725.                         +   " "
  726.                         +   String(MONTH[Time.Month])
  727.                         +   " "
  728.                         +   String(Time.Year);    
  729.  
  730.     Time.ShortData      =   String(Time.DayOfTheMonth)
  731.                         +   " "
  732.                         +   String(MONTH[Time.Month])
  733.                         +   " "
  734.                         +   String(Time.Year);  
  735.  
  736.     Time.LongData       =   String(DAY[Time.DayOfTheWeek])
  737.                         +   " "
  738.                         +   String(Time.DayOfTheMonth)
  739.                         +   "/"
  740.                         +   String(Time.Month)
  741.                         +   "/"
  742.                         +   String(Time.Year);  
  743.  
  744.     String Buffor = "NULL";
  745.  
  746.     if(Time.DayOfTheMonth < 10)
  747.     {
  748.         Buffor = "0";
  749.         Buffor += Time.DayOfTheMonth;
  750.     }
  751.     else Buffor = Time.DayOfTheMonth;
  752.  
  753.     Buffor += "/";
  754.  
  755.     if(Time.Month < 10)
  756.     {
  757.         Buffor += "0";
  758.         Buffor += Time.Month;
  759.     }
  760.     else Buffor += Time.Month;
  761.    
  762.     Buffor += "/";
  763.     Buffor += Time.Year;    
  764.  
  765.     Time.TFT_Data = Buffor;
  766. }
  767.  
  768. // ------------------------------------------------------------------------------------------------------------------- //
  769. // --- stat Wi-Fi ---------------------------------------------------------------------------------------------------- //
  770. // ------------------------------------------------------------------------------------------------------------------- //
  771.  
  772. void statWiFi()
  773. {
  774.     switch (WiFi.status())
  775.     {
  776.         case WL_NO_SSID_AVAIL:
  777.                             #if SERIAL
  778.                                 #if ENGLISH
  779.                                     Serial.printf("\nConfigured SSID cannot be reached");
  780.                                 #endif
  781.                                 #if POLISH
  782.                                     Serial.printf("\nNie można osiągnąć skonfigurowanego identyfikatora SSID");
  783.                                 #endif
  784.                                 #if GERMANY
  785.                                     Serial.printf("\nKonfigurierte SSID ist nicht erreichbar");
  786.                                 #endif
  787.                             #endif        
  788.                             break;
  789.                            
  790.         case WL_CONNECTED:
  791.                             #if SERIAL
  792.                                 #if ENGLISH
  793.                                     Serial.printf("\nConnection successfully established");
  794.                                     Serial.printf("\nYour IP : %s", WiFi.localIP().toString().c_str());
  795.                                     Serial.printf("\nReceived Signal Strength Indication : %d", WiFi.RSSI());
  796.                                 #endif
  797.                                 #if POLISH
  798.                                     Serial.printf("\nPomyślnie nawiązano połączenie");
  799.                                     Serial.printf("\nTwój adres IP : %s", WiFi.localIP().toString().c_str());
  800.                                     Serial.printf("\nWskazanie siły odbieranego sygnału : %d", WiFi.RSSI());
  801.                                 #endif
  802.                                 #if GERMANY
  803.                                     Serial.printf("\nVerbindung erfolgreich hergestellt");
  804.                                     Serial.printf("\nDeine IP-Adresse : %s", WiFi.localIP().toString().c_str());
  805.                                     Serial.printf("\nAnzeige der empfangenen Signalstärke : %d", WiFi.RSSI());                                
  806.                                 #endif
  807.                             #endif
  808.                             break;
  809.                            
  810.         case WL_CONNECT_FAILED:
  811.                             #if SERIAL
  812.                                 #if ENGLISH
  813.                                     Serial.printf("\nConnection failed");
  814.                                 #endif
  815.                                 #if POLISH
  816.                                     Serial.printf("\nPołączenie nieudane");
  817.                                 #endif
  818.                                 #if GERMANY
  819.                                     Serial.printf("\nVerbindung fehlgeschlagen");
  820.                                 #endif
  821.                             #endif
  822.                             break;
  823.     }      
  824. }
  825.  
  826. // ------------------------------------------------------------------------------------------------------------------- //
  827. // --- init Wi-Fi ---------------------------------------------------------------------------------------------------- //
  828. // ------------------------------------------------------------------------------------------------------------------- //
  829.  
  830. void initWiFi()
  831. {
  832.     WiFi.mode(WIFI_STA);
  833.     WiFi.begin(ssid, password);
  834.  
  835.     #if SERIAL    
  836.         #if ENGLISH
  837.             Serial.printf("\nConnecting to WiFi ..");
  838.         #endif
  839.         #if POLISH
  840.             Serial.printf("\nŁącze z siecią WiFi ..");
  841.         #endif
  842.         #if GERMANY
  843.             Serial.printf("\nNetzwerkverbindung mit WLAN ..");
  844.         #endif
  845.     #endif
  846.    
  847.     while (WiFi.status() != WL_CONNECTED)
  848.     {
  849.         Serial.print('.');
  850.         delay(200);
  851.     }
  852.  
  853.     statWiFi();
  854.        
  855.     WiFi.setAutoReconnect(true);
  856.     WiFi.persistent(true);
  857. }
  858.  
  859. // ------------------------------------------------------------------------------------------------------------------- //
  860. // --- reconect Wi-Fi ------------------------------------------------------------------------------------------------ //
  861. // ------------------------------------------------------------------------------------------------------------------- //
  862.  
  863. void reconectWifi()
  864. {
  865.     unsigned long currentMillis = millis();
  866.    
  867.     if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval))
  868.     {
  869.         #if SERIAL
  870.             #if ENGLISH
  871.                 Serial.println("Reconnecting to WiFi...");
  872.             #endif
  873.             #if POLISH
  874.                 Serial.println("Ponowne łączenie z Wi-Fi...");
  875.             #endif
  876.             #if GERMANY
  877.                 Serial.println("Erneut mit WLAN verbinden...");
  878.             #endif
  879.         #endif
  880.        
  881.         WiFi.disconnect();
  882.         WiFi.begin(ssid, password);
  883.        
  884.         statWiFi();
  885.        
  886.         previousMillis = currentMillis;
  887.   }
  888. }
  889.  
  890. // ------------------------------------------------------------------------------------------------------------------- //
  891. // --- schedulerInit ------------------------------------------------------------------------------------------------- //
  892. // ------------------------------------------------------------------------------------------------------------------- //
  893.  
  894. void scheluderInit()
  895. {
  896.     runner.init();                                       // inicjalizuj scheluder
  897.                                                                                  
  898.     runner.addTask(task_0);                              // dodaj zadanie do scheluder
  899.     task_0.enable();                                     // włącz zadanie do scheluder
  900.     runner.addTask(task_1);                              // dodaj zadanie do scheluder
  901.     task_1.enable();                                     // włącz zadanie do scheluder
  902.     runner.addTask(task_2);                              // dodaj zadanie do scheluder
  903.     task_2.enable();                                     // włącz zadanie do scheluder
  904.     runner.addTask(task_3);                              // dodaj zadanie do scheluder
  905.     task_3.enable();                                     // włącz zadanie do scheluder
  906.     runner.addTask(task_4);                              // dodaj zadanie do scheluder
  907.     task_4.enable();                                     // włącz zadanie do scheluder
  908.     runner.addTask(task_5);                              // dodaj zadanie do scheluder
  909.     task_5.enable();                                     // włącz zadanie do scheluder
  910.     runner.addTask(task_6);                              // dodaj zadanie do scheluder
  911.     task_6.enable();                                     // włącz zadanie do scheluder  
  912. }
  913.  
  914. // ------------------------------------------------------------------------------------------------------------------- //
  915. // --- S E T U P --- T F T --- I N I T ------------------------------------------------------------------------------- //
  916. // ------------------------------------------------------------------------------------------------------------------- //
  917.  
  918. void TFT_Init()
  919. {
  920.     tft.begin();
  921.     tft.setRotation(1);
  922.    
  923.     if(!night_mode) TFT_DrawPanel();    
  924.     else
  925.     if(night_mode) TFT_ShowStars();
  926. }
  927.  
  928. // ------------------------------------------------------------------------------------------------------------------- //
  929. // --- S E T U P ----------------------------------------------------------------------------------------------------- //
  930. // ------------------------------------------------------------------------------------------------------------------- //
  931.  
  932. void setup()
  933. {
  934.     #if SERIAL
  935.         Serial.begin(SerialSpeed);
  936.     #endif
  937.  
  938.     delay(200);
  939.        
  940.     tools.TypeWriter("Project by Tomasz Majcher", 100, true);  
  941.     tools.TypeWriter("Clock version 2.30", 100);
  942.     tools.TypeWriter("Tools version 0.01", 100);
  943.     tools.BreakLine();
  944.    
  945.     initWiFi();
  946.     TFT_Init();
  947.     scheluderInit();
  948.  
  949.     AM2320.begin();                         // AM2320 sensor start
  950.     dht.setup(DHTpin, DHTesp::DHT11);       // DHT11 sensor start
  951.  
  952.     // stars generator ---------------------------------------------------- //
  953.    
  954.     za = random(256);
  955.     zb = random(256);
  956.     zc = random(256);
  957.     zx = random(256);
  958.  
  959.     Task6Callback();
  960. }
  961.  
  962. // ------------------------------------------------------------------------------------------------------------------- //
  963. // --- L O O P ------------------------------------------------------------------------------------------------------- //
  964. // ------------------------------------------------------------------------------------------------------------------- //
  965.  
  966. void loop()
  967. {
  968.     runner.execute();     // scheluder init
  969.     reconectWifi();       // check Wi-Fi status
  970.  
  971.     if(night_mode) TFT_ShowStars();
  972. }
  973.  
  974. // ------------------------------------------------------------------------------------------------------------------- //
  975. // --- D R A W   P A N E L   T F T ----------------------------------------------------------------------------------- //
  976. // ------------------------------------------------------------------------------------------------------------------- //
  977.  
  978. void TFT_DrawPanel()
  979. {
  980.     tft.fillScreen(TFT_MODE_BACKGROUND);                                                     // BACKGROUND COLOR
  981.     tft.drawFastVLine(x_min+frame,    y_min+frame,    y_max-2*(frame),  TFT_MODE_COLOR);     // LEFT LINE
  982.     tft.drawFastVLine(x_min+frame+1,  y_min+frame+1,  y_max-2*(frame),  TFT_MODE_COLOR);     // LEFT LINE
  983.     tft.drawFastVLine(x_max-frame,    y_min+frame,    y_max-2*(frame),  TFT_MODE_COLOR);     // RIGHT LINE
  984.     tft.drawFastVLine(x_max-frame-1,  y_min+frame+1,  y_max-2*(frame),  TFT_MODE_COLOR);     // RIGHT LINE
  985.     tft.drawFastHLine(x_min+frame,    y_min+frame,    x_max-2*(frame),  TFT_MODE_COLOR);     // UP LINE
  986.     tft.drawFastHLine(x_min+frame,    y_min+frame+1,  x_max-2*(frame),  TFT_MODE_COLOR);     // UP LINE
  987.     tft.drawFastHLine(x_min+frame,    y_max-frame,    x_max-2*(frame),  TFT_MODE_COLOR);     // DOWN LINE
  988.     tft.drawFastHLine(x_min+frame+1,  y_max-frame-1,  x_max-2*(frame),  TFT_MODE_COLOR);     // DOWN LINE
  989.     tft.drawFastHLine(x_min+frame,    y_min+frame+60,    x_max-2*(frame),  TFT_MODE_COLOR);  // CLOCK LINE DOWN
  990.     tft.drawFastHLine(x_min+frame,    y_min+frame+61,    x_max-2*(frame),  TFT_MODE_COLOR);  // CLOCK LINE DOWN
  991.     //tft.drawFastVLine(x_min+157,      y_min+frame+1,     60,  TFT_MODE_COLOR);             // CLOCK LINE RIGHT
  992.     //tft.drawFastVLine(x_min+156,      y_min+frame+1,     60,  TFT_MODE_COLOR);             // CLOCK LINE RIGHT
  993.     tft.drawFastHLine(x_min+frame,    y_min+frame+80,    x_max-2*(frame),  TFT_MODE_COLOR);  // PROGRES LINE DOWN
  994.     tft.drawFastHLine(x_min+frame,    y_min+frame+81,    x_max-2*(frame),  TFT_MODE_COLOR);  // PROGRES LINE DOWN
  995.     tft.drawFastHLine(x_min+frame,    y_min+frame+150,    x_max-2*(frame),  TFT_MODE_COLOR); // SENSOR LINE
  996.     tft.drawFastHLine(x_min+frame,    y_min+frame+151,    x_max-2*(frame),  TFT_MODE_COLOR); // SENSOR LINE
  997.     tft.drawFastVLine(x_min+165,      85,     150,  TFT_MODE_COLOR);                         // SENSOR LINE
  998.     tft.drawFastVLine(x_min+166,      85,     150,  TFT_MODE_COLOR);                         // SENSOR LINE
  999. }
  1000.  
  1001. // ------------------------------------------------------------------------------------------------------------------- //
  1002. // --- T F T   S H O W    TEMPERATURE -------------------------------------------------------------------------------- //
  1003. // ------------------------------------------------------------------------------------------------------------------- //
  1004.  
  1005. void TFT_ShowTemperature()
  1006. {
  1007.     // ----------------------------------------------------------------- //
  1008.     // --- show temperature INSIDE from AM2320 sensor ------------------ //
  1009.     // ----------------------------------------------------------------- //
  1010.  
  1011.     tft.setTextColor(TFT_MODE_COLOR, TFT_MODE_BACKGROUND);
  1012.    
  1013.     #if POLISH
  1014.         tft.drawCentreString("Temperatura IN",80,95,2);
  1015.     #endif
  1016.  
  1017.     #if GERMANY
  1018.         tft.drawCentreString("Temperatur IN",80,95,2);
  1019.     #endif
  1020.  
  1021.     #if ENGLISH
  1022.         tft.drawCentreString("Temperature IN",80,95,2);
  1023.     #endif
  1024.    
  1025.     String Buffor = String(sensor.temperature) + "`C";
  1026.     tft.drawCentreString(Buffor,80,120,4);
  1027.  
  1028.     // ----------------------------------------------------------------- //
  1029.     // --- show temperature OUTSIDE from DHT11 sensor ------------------ //
  1030.     // ----------------------------------------------------------------- //    
  1031.    
  1032.     tft.setTextColor(TFT_MODE_COLOR, TFT_MODE_BACKGROUND);
  1033.  
  1034.     #if POLISH
  1035.         tft.drawCentreString("Temperatura OUT",240,95,2);
  1036.     #endif
  1037.  
  1038.     #if GERMANY
  1039.         tft.drawCentreString("Temperatur OUT",240,95,2);
  1040.     #endif
  1041.  
  1042.     #if ENGLISH
  1043.         tft.drawCentreString("Temperature OUT",240,95,2);
  1044.     #endif
  1045.    
  1046.     Buffor = String(myDHT.temperature) + "`C";
  1047.     tft.drawCentreString(Buffor,240,120,4);    
  1048.    
  1049.     // ----------------------------------------------------------------- //
  1050.    
  1051. }
  1052.  
  1053. // ------------------------------------------------------------------------------------------------------------------- //
  1054. // --- T F T   S H O W    HUMIDITY ----------------------------------------------------------------------------------- //
  1055. // ------------------------------------------------------------------------------------------------------------------- //
  1056.  
  1057. void TFT_ShowHumidity()
  1058. {
  1059.     // ----------------------------------------------------------------- //
  1060.     // --- show humidity INSIDE from AM2320 sensor --------------------- //
  1061.     // ----------------------------------------------------------------- //
  1062.  
  1063.     tft.setTextColor(TFT_MODE_COLOR, TFT_MODE_BACKGROUND);
  1064.  
  1065.     #if POLISH
  1066.         tft.drawCentreString("Wilgotnosc IN",80,165,2);
  1067.     #endif
  1068.  
  1069.     #if GERMANY
  1070.         tft.drawCentreString("Feuchtigkeit IN",80,165,2);
  1071.     #endif
  1072.  
  1073.     #if ENGLISH
  1074.         tft.drawCentreString("Humidity IN",80,165,2);
  1075.     #endif
  1076.    
  1077.     String Buffor = String(sensor.humidity) + "%";
  1078.     tft.drawCentreString(Buffor,80,190,4);
  1079.  
  1080.     // ----------------------------------------------------------------- //
  1081.     // --- show humidity OUTSIDE from DHT11 sensor --------------------- //
  1082.     // ----------------------------------------------------------------- //
  1083.    
  1084.     tft.setTextColor(TFT_MODE_COLOR, TFT_MODE_BACKGROUND);
  1085.  
  1086.     #if POLISH
  1087.         tft.drawCentreString("Wilgotnosc OUT",240,165,2);
  1088.     #endif
  1089.    
  1090.     #if GERMANY
  1091.         tft.drawCentreString("Feuchtigkeit OUT",240,165,2);
  1092.     #endif
  1093.  
  1094.     #if ENGLISH
  1095.         tft.drawCentreString("Humidity OUT",240,165,2);
  1096.     #endif
  1097.  
  1098.    
  1099.     Buffor = String(myDHT.humidity) + "%";
  1100.     tft.drawCentreString(Buffor,240,190,4);
  1101.  
  1102.     // ----------------------------------------------------------------- //
  1103. }
  1104.  
  1105. // ------------------------------------------------------------------------------------------------------------------- //
  1106. // --- T F T   S H O W    D A T E -=---------------------------------------------------------------------------------- //
  1107. // ------------------------------------------------------------------------------------------------------------------- //
  1108.  
  1109. void TFT_ShowDate()
  1110. {
  1111.     tft.setTextColor(TFT_MODE_COLOR, TFT_MODE_BACKGROUND);    
  1112.     //tft.drawCentreString(DAY[Time.DayOfTheWeek], 240, 10, 4);    
  1113.     tft.drawCentreString(Time.TFT_Data, 240, 25, 4);  
  1114. }
  1115.  
  1116. // ------------------------------------------------------------------------------------------------------------------- //
  1117. // --- T F T   S H O W    T I M E ------------------------------------------------------------------------------------ //
  1118. // ------------------------------------------------------------------------------------------------------------------- //
  1119.  
  1120. void TFT_ShowTime()
  1121. {
  1122.     if (!night_mode)
  1123.     {
  1124.         tft.setTextColor(TFT_MODE_COLOR, TFT_MODE_BACKGROUND);            
  1125.         tft.drawString(Time.TFT_Time, 12, 12, 7);      
  1126.     }
  1127.     else
  1128.     if (night_mode)
  1129.     {
  1130.         tft.setTextColor(TFT_WHITE, TFT_BLACK);            
  1131.         tft.drawCentreString(Time.TFT_Time, 160, 90, 7);      
  1132.     }
  1133. }
  1134.  
  1135. // ------------------------------------------------------------------------------------------------------------------- //
  1136. // --- T F T   P R O G R E S   T I M E ------------------------------------------------------------------------------- //
  1137. // ------------------------------------------------------------------------------------------------------------------- //
  1138.  
  1139. void TFT_ShowProgres()
  1140. {
  1141.     int progres = Time.Second;
  1142.     static bool F_Clear = false;
  1143.  
  1144.     if (progres>50) F_Clear = true;
  1145.  
  1146.     if ( !progres && F_Clear )
  1147.     {
  1148.         tft.fillRect(13, 70, 300, 12, TFT_MODE_BACKGROUND);                    // fast clear progres bar    
  1149.         F_Clear = false;
  1150.     }
  1151.     else
  1152.     if ( progres < 5 && F_Clear )
  1153.     {
  1154.         tft.fillRect(13, 70, 300, 12, TFT_MODE_BACKGROUND);                    // fast clear progres bar    
  1155.         F_Clear = false;
  1156.     }
  1157.  
  1158.     for(int i = 0; i < progres; i++)
  1159.     {
  1160.         tft.fillRect(13+(i*5), 70, 3, 12, TFT_MODE_COLOR);                       // fast draw progres bar
  1161.     }
  1162.  
  1163. }
  1164.  
  1165. // ------------------------------------------------------------------------------------------------------------------- //
  1166. // --- T F T   S H O W    B U G -  ----------------------------------------------------------------------------------- //
  1167. // ------------------------------------------------------------------------------------------------------------------- //
  1168.  
  1169. void TFT_ShowBug()
  1170. {
  1171.     static int position_x = 0;
  1172.     static int position_y = 0;
  1173.     static bool step_1 = true;
  1174.     static bool step_2 = false;
  1175.     static bool step_3 = false;
  1176.     static bool step_4 = false;    
  1177.  
  1178.     if (step_1)
  1179.     {
  1180.         if (position_x<140)
  1181.         {
  1182.             tft.fillRect(165+position_x, 15, 1, 5, TFT_MODE_BACKGROUND);
  1183.             position_x ++;
  1184.             tft.fillRect(165+position_x, 15, 5, 5, TFT_MODE_COLOR);
  1185.         }        
  1186.         else
  1187.         {
  1188.             step_1 = false;   // stop move bug to right
  1189.             step_2 = true;    // start move bug to down
  1190.         }            
  1191.     }
  1192.     else
  1193.     if (step_2)
  1194.     {
  1195.         if (position_y<35)
  1196.         {
  1197.             tft.fillRect(165+position_x, 15+position_y, 5, 1, TFT_MODE_BACKGROUND);
  1198.             position_y ++;
  1199.             tft.fillRect(165+position_x, 15+position_y, 5, 5, TFT_MODE_COLOR);      
  1200.         }
  1201.         else
  1202.         {
  1203.             step_2 = false;   // stop move bug to down
  1204.             step_3 = true;    // start move bug to left
  1205.         }
  1206.     }
  1207.     else
  1208.     if (step_3)
  1209.     {
  1210.         if (position_x>0)
  1211.         {
  1212.             tft.fillRect(165+position_x+5, 15+position_y, 1, 5, TFT_MODE_BACKGROUND);
  1213.             position_x --;
  1214.             tft.fillRect(165+position_x, 15+position_y, 5, 5, TFT_MODE_COLOR);  
  1215.         }
  1216.         else
  1217.         {
  1218.             tft.fillRect(165+position_x+5, 15+position_y, 1, 5, TFT_MODE_BACKGROUND);
  1219.             step_3 = false;
  1220.             step_4 = true;
  1221.         }
  1222.     }
  1223.     else
  1224.     if (step_4)
  1225.     {
  1226.         if (position_y>0)
  1227.         {
  1228.             tft.fillRect(165+position_x, 15+position_y+5, 5, 1, TFT_MODE_BACKGROUND);
  1229.             position_y --;
  1230.             tft.fillRect(165+position_x, 15+position_y, 5, 5, TFT_MODE_COLOR);        
  1231.         }
  1232.         else
  1233.         {
  1234.             tft.fillRect(165+position_x, 15+position_y+5, 5, 1, TFT_MODE_BACKGROUND);
  1235.             step_4 = false;
  1236.             step_1 = true;
  1237.         }
  1238.     }
  1239. }
  1240.  
  1241. // ------------------------------------------------------------------------------------------------------------------- //
  1242. // --- T F T   S H O W    S T A R S ---------------------------------------------------------------------------------- //
  1243. // ------------------------------------------------------------------------------------------------------------------- //
  1244.  
  1245. void TFT_ShowStars()
  1246. {
  1247.     uint8_t spawnDepthVariation = 255;
  1248.  
  1249.     if (night_mode) TFT_ShowTime();
  1250.  
  1251.     for(int i = 0; i < NSTARS; ++i)
  1252.     {
  1253.         if (sz[i] <= 1)
  1254.         {
  1255.             sx[i] = 160 - 120 + rng();
  1256.             sy[i] = rng();
  1257.             sz[i] = spawnDepthVariation--;
  1258.         }
  1259.         else
  1260.         {
  1261.             int old_screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160;
  1262.             int old_screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120;
  1263.      
  1264.             tft.drawPixel(old_screen_x, old_screen_y,TFT_BLACK);
  1265.  
  1266.             sz[i] -= 2;
  1267.            
  1268.             if (sz[i] > 1)
  1269.             {
  1270.                 int screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160;
  1271.                 int screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120;
  1272.  
  1273.                 if (screen_x >= 0 && screen_y >= 0 && screen_x < 320 && screen_y < 240)
  1274.                 {
  1275.                     uint8_t r, g, b;
  1276.                     r = g = b = 255 - sz[i];
  1277.                     tft.drawPixel(screen_x, screen_y, tft.color565(r,g,b));
  1278.                 }
  1279.                 else sz[i] = 0; // Out of screen, die.
  1280.             }
  1281.         }
  1282.     }  
  1283. }
  1284.  
  1285. // ------------------------------------------------------------------------------------------------------------------- //
  1286. // --- E N D  -------------------------------------------------------------------------------------------------------- //
  1287. // ------------------------------------------------------------------------------------------------------------------- //
Advertisement
Add Comment
Please, Sign In to add comment