Advertisement
PowerTGS440

ESP_martyca.h

Feb 15th, 2021
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.62 KB | None | 0 0
  1. // --- File name : matryca.h --- //
  2. // ------------------------------------------------------------------------------------------------------------------------ //
  3. // --- class Matryca --- version. ESP --- //
  4. // ------------------------------------------------------------------------------------------------------------------------ //
  5. // klasa zbudowana dla urządzeń ESP2886 i ESP32
  6. // build start : 13.02.2021
  7. // licencja :
  8. // e-mail : powerTGS440@gmail.com
  9. // www : https://arudino-code.blogspot.com/
  10. // ------------------------------------------------------------------------------------------------------------------------ //
  11. // --- H I S T O R Y L O G --- //
  12. // ------------------------------------------------------------------------------------------------------------------------ //
  13. //
  14. // v0.017 - monday afrernoon no. 5 --- dodano : ShowWind(); --- metoda publiczna
  15. // v0.016 - monday afternoon no. 4 --- dodano : ShowHumidity(); --- metoda publiczna
  16. // v0.015 - monday afternoon no. 3 --- dodano : ShowPressure(); --- metoda publiczna
  17. // v0.014 - monday afternoon no. 2 --- dodano : ShowTemperature(); --- metoda publiczna
  18. // v0.013 - monday afternoon no. 1 --- dodano : Time2Char(,,,) --- metoda publiczna
  19. // v0.012 - monday morning no. 5 --- dodano : ShowShortTime(); --- metoda publiczna
  20. // v0.011 - monday morning no. 4 --- dodano : Time2Char(,,); --- metoda publiczna
  21. // v0.010 - monday morning no. 3 --- dodano : Date2Char(,,,); --- metoda publiczna
  22. // v0.009 - monday morning no. 2 --- dodano : ShowShortDate(); --- metoda publiczna
  23. // v0.008 - monday morning no. 1 --- dodano : ShowLongDate(); --- metoda publiczna
  24. // v0.007 - frosty Sunday no. 7 --- dodano : Generator liczb losowych ESP8266TrueRandom
  25. // v0.006 - frosty Sunday no. 6 --- BUILD : RandomDemo(); --- metoda publiczna
  26. // v0.005 - frosty Sunday no. 5 --- BUILD : EffectDemo(); --- metoda publiczna
  27. // v0.004 - frosty Sunday no. 4 --- BUILD : SpriteDemo(); --- metoda publiczna
  28. // v0.003 - frosty Sunday no. 3 --- IMPORT : EFFECT
  29. // v0.002 - frosty Sunday no. 2 --- IMPORT : SPRITE
  30. // v0.001 - frosty Sunday no. 1 --- przebudowa z istniejącej biblioteki matrix.h dla Arduino
  31. // ------------------------------------------------------------------------------------------------------------------------ //
  32. // --- I N C L U D E --- //
  33. // ------------------------------------------------------------------------------------------------------------------------ //
  34.  
  35. #include <ESP8266WiFi.h>
  36. #include <Arduino.h>
  37. #include <MD_Parola.h>
  38. #include <MD_MAX72xx.h>
  39. #include <SPI.h>
  40. #include "ESP8266TrueRandom.h"
  41.  
  42. // ------------------------------------------------------------------------------------------------------------------------ //
  43. // --- D E F I N E --- //
  44. // ------------------------------------------------------------------------------------------------------------------------ //
  45.  
  46. #define TERMINAL 1 // 0 - wyłącz SERIAL, 1 - włącz SERIAL ---- //
  47. #define USBSPEED 57600 // 57600 - prędkość Terminala szeregowego - //
  48.  
  49. // ------------------------------------------------------------------------------------------------------------------------ //
  50. // --- D E F I N E --- jeśli LANGUAGE jest 0 to język Polski, jeśli LANGUAGE jest 1 to język ANGIELSKI --- //
  51. // ------------------------------------------------------------------------------------------------------------------------ //
  52.  
  53. #define LANGUAGE 0
  54.  
  55. #if LANGUAGE
  56. #define POLISH 0
  57. #define ENGLISH 1
  58. #else
  59. #define POLISH 1
  60. #define ENGLISH 0
  61. #endif
  62.  
  63. // ------------------------------------------------------------------------------------------------------------------------ //
  64. // M E S S E G E D E F I N I T I O N ------------------------------------------------------------------------------------ //
  65. // ------------------------------------------------------------------------------------------------------------------------ //
  66. // Moje napisy do wyświetlenia -------------------------------------------------------------------------------------------- //
  67. // ------------------------------------------------------------------------------------------------------------------------ //
  68.  
  69. char MSG_00 [] = "K A B O O M";
  70. const char MSG_01 [] = "M A R C I N";
  71. const char MSG_02 [] = "MARCIN SCP!";
  72. const char MSG_03 [] = "S C P" ;
  73. const char MSG_04 [] = "GAME OVER";
  74. const char MSG_05 [] = "P O R T A L";
  75. const char MSG_06 [] = "KNIGHTS :3";
  76. const char MSG_07 [] = "HELLO MARCIN";
  77. const char MSG_08 [] = "I S L A N D";
  78. const char MSG_09 [] = "MINECRAFT";
  79. const char MSG_10 [] = "TIME 4 YOU";
  80. const char MSG_11 [] = "code in c++";
  81.  
  82. const char * const MSG [] =
  83. {
  84. MSG_00, MSG_01, MSG_02, MSG_03, MSG_04, MSG_05,
  85. MSG_06, MSG_07, MSG_08, MSG_09, MSG_10, MSG_11
  86. };
  87.  
  88. // ------------------------------------------------------------------------------------------------------------------------ //
  89. // S P R I T E D E F I N I T I O N -------------------------------------------------------------------------------------- //
  90. // ------------------------------------------------------------------------------------------------------------------------ //
  91. // P A C M A N D E F I N I T I O N -------------------------------------------------------------------------------------- //
  92. // ------------------------------------------------------------------------------------------------------------------------ //
  93.  
  94. const uint8_t F_PMAN1 = 6; // rozmiar duszka PACMAN ----------------- //
  95. const uint8_t W_PMAN1 = 8; // rozmiar duszka PACMAN ----------------- //
  96. static const uint8_t pacman1[F_PMAN1 * W_PMAN1] PROGMEM = // definicja animacji PACMAN ------------- //
  97. {
  98. 0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c,
  99. 0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
  100. 0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  101. 0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  102. 0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  103. 0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
  104. };
  105. // 293756 / 28612
  106. // ------------------------------------------------------------------------------------------------------------------------ //
  107. // S P R I T E : W A V E / W O R M D E F I N I T I O N ---------------------------------------------------------- //
  108. // ------------------------------------------------------------------------------------------------------------------------ //
  109.  
  110. const uint8_t F_WAVE = 14;
  111. const uint8_t W_WAVE = 14;
  112. static const uint8_t wave [F_WAVE * W_WAVE] PROGMEM =
  113. {
  114. 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10,
  115. 0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20,
  116. 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40,
  117. 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  118. 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40,
  119. 0x40, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
  120. 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10,
  121. 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08,
  122. 0x08, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04,
  123. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x02,
  124. 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01,
  125. 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02,
  126. 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04,
  127. 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x08,
  128. };
  129.  
  130. // ------------------------------------------------------------------------------------------------------------------------ //
  131. // S P R I T E : G H O S T D E F I N I T I O N ---------------------------------------------------------------------- //
  132. // ------------------------------------------------------------------------------------------------------------------------ //
  133.  
  134. const uint8_t F_PMAN2 = 6; // rozmiar duszka GHOST ----------------- //
  135. const uint8_t W_PMAN2 = 18; // rozmiar duszka GHOST ----------------- //
  136. static const uint8_t pacman2[F_PMAN2 * W_PMAN2] PROGMEM = // animacja DUCH goni PACMANA ----------- //
  137. {
  138. 0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  139. 0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  140. 0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  141. 0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  142. 0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  143. 0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  144. };
  145.  
  146. // ------------------------------------------------------------------------------------------------------------------------ //
  147. // S P R I T E : R O L L I N G 1 S Q U A R E D E F I N I T I O N -------------------------------------------- //
  148. // ------------------------------------------------------------------------------------------------------------------------ //
  149.  
  150. const uint8_t F_ROLL1 = 4;
  151. const uint8_t W_ROLL1 = 8;
  152. static const uint8_t roll1[F_ROLL1 * W_ROLL1] PROGMEM =
  153. {
  154. 0xff, 0x8f, 0x8f, 0x8f, 0x81, 0x81, 0x81, 0xff,
  155. 0xff, 0xf1, 0xf1, 0xf1, 0x81, 0x81, 0x81, 0xff,
  156. 0xff, 0x81, 0x81, 0x81, 0xf1, 0xf1, 0xf1, 0xff,
  157. 0xff, 0x81, 0x81, 0x81, 0x8f, 0x8f, 0x8f, 0xff,
  158. };
  159.  
  160. // ------------------------------------------------------------------------------------------------------------------------ //
  161. // S P R I T E : R O L L I N G 2 O C T A G O N D E F I N I T I O N -------------------------------------------- //
  162. // ------------------------------------------------------------------------------------------------------------------------ //
  163.  
  164. const uint8_t F_ROLL2 = 4;
  165. const uint8_t W_ROLL2 = 8;
  166. static const uint8_t roll2 [F_ROLL2 * W_ROLL2] PROGMEM =
  167. {
  168. 0x3c, 0x4e, 0x8f, 0x8f, 0x81, 0x81, 0x42, 0x3c,
  169. 0x3c, 0x72, 0xf1, 0xf1, 0x81, 0x81, 0x42, 0x3c,
  170. 0x3c, 0x42, 0x81, 0x81, 0xf1, 0xf1, 0x72, 0x3c,
  171. 0x3c, 0x42, 0x81, 0x81, 0x8f, 0x8f, 0x4e, 0x3c,
  172. };
  173.  
  174. // ------------------------------------------------------------------------------------------------------------------------ //
  175. // S P R I T E : S P A C E D L I N E S D E F I N I T I O N ---------------------------------------------------- //
  176. // ------------------------------------------------------------------------------------------------------------------------ //
  177.  
  178. const uint8_t F_LINES = 3;
  179. const uint8_t W_LINES = 8;
  180. static const uint8_t lines [F_LINES * W_LINES] PROGMEM =
  181. {
  182. 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00,
  183. 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
  184. 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
  185. };
  186.  
  187. // ------------------------------------------------------------------------------------------------------------------------ //
  188. // S P R I T E : A R R O W F A D I N G D E F I N I T I O N --------------------------------------------------- //
  189. // ------------------------------------------------------------------------------------------------------------------------ //
  190.  
  191. const uint8_t F_ARROW1 = 3;
  192. const uint8_t W_ARROW1 = 10;
  193. static const uint8_t arrow1 [F_ARROW1 * W_ARROW1] PROGMEM =
  194. {
  195. 0x18, 0x3c, 0x7e, 0xff, 0x7e, 0x00, 0x00, 0x3c, 0x00, 0x00,
  196. 0x18, 0x3c, 0x7e, 0xff, 0x00, 0x7e, 0x00, 0x00, 0x18, 0x00,
  197. 0x18, 0x3c, 0x7e, 0xff, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x18,
  198. };
  199.  
  200. // ------------------------------------------------------------------------------------------------------------------------ //
  201. // S P R I T E : A R R O W F A D I N G O U T S I D E D E F I N I T I O N ---------------------------------- //
  202. // ------------------------------------------------------------------------------------------------------------------------ //
  203.  
  204. const uint8_t F_ARROW2 = 3;
  205. const uint8_t W_ARROW2 = 9;
  206. static const uint8_t arrow2 [F_ARROW2 * W_ARROW2] PROGMEM =
  207. {
  208. 0x18, 0x3c, 0x7e, 0xe7, 0x00, 0x00, 0xc3, 0x00, 0x00,
  209. 0x18, 0x3c, 0x7e, 0xe7, 0xe7, 0x00, 0x00, 0x81, 0x00,
  210. 0x18, 0x3c, 0x7e, 0xe7, 0x00, 0xc3, 0x00, 0x00, 0x81,
  211. };
  212.  
  213. // ------------------------------------------------------------------------------------------------------------------------ //
  214. // S P R I T E : Ż A G L Ó W K A S H I P D E F I N I T I O N ------------------------------------------------- //
  215. // ------------------------------------------------------------------------------------------------------------------------ //
  216.  
  217. const uint8_t F_SAILBOAT = 1;
  218. const uint8_t W_SAILBOAT = 11;
  219. static const uint8_t sailboat[F_SAILBOAT * W_SAILBOAT] PROGMEM =
  220. {
  221. 0x10, 0x30, 0x58, 0x94, 0x92, 0x9f, 0x92, 0x94, 0x98, 0x50, 0x30,
  222. };
  223.  
  224. // ------------------------------------------------------------------------------------------------------------------------ //
  225. // S P R I T E : T I T A N I C S T E A M D E F I N I T I O N ------------------------------------------------- //
  226. // ------------------------------------------------------------------------------------------------------------------------ //
  227.  
  228. const uint8_t F_STEAMBOAT = 2;
  229. const uint8_t W_STEAMBOAT = 11;
  230. const uint8_t steamboat[F_STEAMBOAT * W_STEAMBOAT] PROGMEM =
  231. {
  232. 0x10, 0x30, 0x50, 0x9c, 0x9e, 0x90, 0x91, 0x9c, 0x9d, 0x90, 0x71,
  233. 0x10, 0x30, 0x50, 0x9c, 0x9c, 0x91, 0x90, 0x9d, 0x9e, 0x91, 0x70,
  234. };
  235.  
  236. // ------------------------------------------------------------------------------------------------------------------------ //
  237. // S P R I T E : H E A R T D E F I N I T I O N ------------------------------------------------------------------ //
  238. // ------------------------------------------------------------------------------------------------------------------------ //
  239.  
  240. const uint8_t F_HEART = 5;
  241. const uint8_t W_HEART = 9;
  242. static const uint8_t heart[F_HEART * W_HEART] PROGMEM =
  243. {
  244. 0x0e, 0x11, 0x21, 0x42, 0x84, 0x42, 0x21, 0x11, 0x0e,
  245. 0x0e, 0x1f, 0x33, 0x66, 0xcc, 0x66, 0x33, 0x1f, 0x0e,
  246. 0x0e, 0x1f, 0x3f, 0x7e, 0xfc, 0x7e, 0x3f, 0x1f, 0x0e,
  247. 0x0e, 0x1f, 0x33, 0x66, 0xcc, 0x66, 0x33, 0x1f, 0x0e,
  248. 0x0e, 0x11, 0x21, 0x42, 0x84, 0x42, 0x21, 0x11, 0x0e,
  249. };
  250.  
  251. // ------------------------------------------------------------------------------------------------------------------------ //
  252. // S P R I T E : N A J E Ż D Z C A Z K O S M O S U D E F I N I T I O N -------------------------------------- //
  253. // ------------------------------------------------------------------------------------------------------------------------ //
  254.  
  255. const uint8_t F_INVADER = 2;
  256. const uint8_t W_INVADER = 10;
  257. static const uint8_t invader[F_INVADER * W_INVADER] PROGMEM =
  258. {
  259. 0x0e, 0x98, 0x7d, 0x36, 0x3c, 0x3c, 0x36, 0x7d, 0x98, 0x0e,
  260. 0x70, 0x18, 0x7d, 0xb6, 0x3c, 0x3c, 0xb6, 0x7d, 0x18, 0x70,
  261. };
  262.  
  263. // ------------------------------------------------------------------------------------------------------------------------ //
  264. // S P R I T E : R A K I E T A Z K O S M O S U D E F I N I T I O N ------------------------------------------ //
  265. // ------------------------------------------------------------------------------------------------------------------------ //
  266.  
  267. const uint8_t F_ROCKET = 2;
  268. const uint8_t W_ROCKET = 11;
  269. static const uint8_t rocket[F_ROCKET * W_ROCKET] PROGMEM =
  270. {
  271. 0x18, 0x24, 0x42, 0x81, 0x99, 0x18, 0x99, 0x18, 0xa5, 0x5a, 0x81,
  272. 0x18, 0x24, 0x42, 0x81, 0x18, 0x99, 0x18, 0x99, 0x24, 0x42, 0x99,
  273. };
  274.  
  275. // ------------------------------------------------------------------------------------------------------------------------ //
  276. // S P R I T E : F I R E B A L L D E F I N I T I O N ------------------------------------------------------------ //
  277. // ------------------------------------------------------------------------------------------------------------------------ //
  278.  
  279. const uint8_t F_FBALL = 2;
  280. const uint8_t W_FBALL = 11;
  281. static const uint8_t fireball[F_FBALL * W_FBALL] PROGMEM =
  282. {
  283. 0x7e, 0xab, 0x54, 0x28, 0x52, 0x24, 0x40, 0x18, 0x04, 0x10, 0x08,
  284. 0x7e, 0xd5, 0x2a, 0x14, 0x24, 0x0a, 0x30, 0x04, 0x28, 0x08, 0x10,
  285. };
  286.  
  287. // ------------------------------------------------------------------------------------------------------------------------ //
  288. // S P R I T E : C H E V R O N D E F I N I T I O N -------------------------------------------------------------- //
  289. // ------------------------------------------------------------------------------------------------------------------------ //
  290.  
  291. const uint8_t F_CHEVRON = 1;
  292. const uint8_t W_CHEVRON = 9;
  293. static const uint8_t chevron[F_CHEVRON * W_CHEVRON] PROGMEM =
  294. {
  295. 0x18, 0x3c, 0x66, 0xc3, 0x99, 0x3c, 0x66, 0xc3, 0x81,
  296. };
  297.  
  298. // ------------------------------------------------------------------------------------------------------------------------ //
  299. // S P R I T E : I D Ą C Y L U D Z I K D E F I N I T I O N ---------------------------------------------------- //
  300. // ------------------------------------------------------------------------------------------------------------------------ //
  301.  
  302. const uint8_t F_WALKER = 5;
  303. const uint8_t W_WALKER = 7;
  304. static const uint8_t walker[F_WALKER * W_WALKER] PROGMEM =
  305. {
  306. 0x00, 0x48, 0x77, 0x1f, 0x1c, 0x94, 0x68,
  307. 0x00, 0x90, 0xee, 0x3e, 0x38, 0x28, 0xd0,
  308. 0x00, 0x00, 0xae, 0xfe, 0x38, 0x28, 0x40,
  309. 0x00, 0x00, 0x2e, 0xbe, 0xf8, 0x00, 0x00,
  310. 0x00, 0x10, 0x6e, 0x3e, 0xb8, 0xe8, 0x00,
  311. };
  312.  
  313. // ------------------------------------------------------------------------------------------------------------------------ //
  314. // S P R I T E : S T R U K T U R A A N I M A C J I d l a D U S Z K Ó W ----------------------------------------- //
  315. // ------------------------------------------------------------------------------------------------------------------------ //
  316.  
  317. struct Sprite
  318. {
  319. const uint8_t *data;
  320. uint8_t width;
  321. uint8_t frames;
  322. };
  323.  
  324. Sprite sprite[] = {
  325. { walker, W_WALKER, F_WALKER },
  326. { invader, W_INVADER, F_INVADER },
  327. { chevron, W_CHEVRON, F_CHEVRON },
  328. { heart, W_HEART, F_HEART },
  329. { arrow1, W_ARROW1, F_ARROW1 },
  330. { steamboat, W_STEAMBOAT, F_STEAMBOAT },
  331. { fireball, W_FBALL, F_FBALL },
  332. { rocket, W_ROCKET, F_ROCKET },
  333. { roll2, W_ROLL2, F_ROLL2 },
  334. { pacman2, W_PMAN2, F_PMAN2 },
  335. { lines, W_LINES, F_LINES },
  336. { roll1, W_ROLL1, F_ROLL1 },
  337. { sailboat, W_SAILBOAT, F_SAILBOAT },
  338. { arrow2, W_ARROW2, F_ARROW2 },
  339. { wave, W_WAVE, F_WAVE },
  340. { pacman1, W_PMAN1, F_PMAN1 }
  341. };
  342.  
  343. // ------------------------------------------------------------------------------------------------------------------------ //
  344. // --- K A T A L O G E F E K T Ó W --- //
  345. // ------------------------------------------------------------------------------------------------------------------------ //
  346.  
  347. struct Effect
  348. {
  349. textEffect_t effect;
  350. uint16_t speed;
  351. uint16_t pause;
  352. }
  353.  
  354. efekt [] =
  355. {
  356. { PA_PRINT, 1, 1 },
  357. { PA_SCROLL_UP, 5, 1 },
  358. { PA_SCROLL_DOWN, 5, 1 },
  359. { PA_SCROLL_LEFT, 5, 1 },
  360. { PA_SCROLL_RIGHT, 5, 1 },
  361. { PA_SPRITE, 5, 1 },
  362. { PA_SLICE, 1, 1 },
  363. { PA_MESH, 20, 1 },
  364. { PA_FADE, 20, 1 },
  365. { PA_DISSOLVE, 7, 1 },
  366. { PA_BLINDS, 7, 1 },
  367. { PA_RANDOM, 3, 1 },
  368. { PA_WIPE, 5, 1 },
  369. { PA_WIPE_CURSOR, 4, 1 },
  370. { PA_SCAN_HORIZ, 4, 1 },
  371. { PA_SCAN_HORIZX, 4, 1 },
  372. { PA_SCAN_VERT, 3, 1 },
  373. { PA_SCAN_VERTX, 3, 1 },
  374. { PA_OPENING, 3, 1 },
  375. { PA_OPENING_CURSOR, 4, 1 },
  376. { PA_CLOSING, 3, 1 },
  377. { PA_CLOSING_CURSOR, 4, 1 },
  378. { PA_SCROLL_UP_LEFT, 7, 1 },
  379. { PA_SCROLL_UP_RIGHT, 7, 1 },
  380. { PA_SCROLL_DOWN_LEFT, 7, 1 },
  381. { PA_SCROLL_DOWN_RIGHT, 7, 1 },
  382. { PA_GROW_UP, 7, 1 },
  383. { PA_GROW_DOWN, 7, 1 }
  384. };
  385.  
  386. // ------------------------------------------------------------------------------------------------------------------------ //
  387. // ALL MATRIX DAY to PROGMEM MEMORY !!! ----------------------------------------------------------------------------------- //
  388. // ------------------------------------------------------------------------------------------------------------------------ //
  389. // jeśli POLISH jest true / if POLISH is true ----------------------------------------------------------------------------- //
  390.  
  391. #if POLISH
  392. const char DAY_00 [] = "Niedziela";
  393. const char DAY_01 [] = "Poniedzialek";
  394. const char DAY_02 [] = "Wtorek";
  395. const char DAY_03 [] = "Sroda";
  396. const char DAY_04 [] = "Czwartek";
  397. const char DAY_05 [] = "Piatek";
  398. const char DAY_06 [] = "Sobota";
  399. const char DAY_07 [] = "Data: ";
  400. #endif
  401.  
  402. // jeśli ENGLISH jest true / if ENGLISH is true -------------------------------------------------------------------------- //
  403. #if ENGLISH
  404. const char DAY_00 [] = "Sunday";
  405. const char DAY_01 [] = "Monday";
  406. const char DAY_02 [] = "Tuesday";
  407. const char DAY_03 [] = "Wednesday";
  408. const char DAY_04 [] = "Thursday";
  409. const char DAY_05 [] = "Friday";
  410. const char DAY_06 [] = "Saturday";
  411. const char DAY_07 [] = "Date: ";
  412. #endif
  413.  
  414. const char * DAY [] =
  415. {
  416. DAY_00, DAY_01, DAY_02, DAY_03, DAY_04, DAY_05,
  417. DAY_06, DAY_07
  418. };
  419.  
  420.  
  421.  
  422. // jeśli POLISH jest true / if ENGLISH is true --------------------------------------------------------------------------- //
  423.  
  424. #if POLISH
  425. const char MONTH_00 [] = "Error";
  426. const char MONTH_01 [] = "Styczen";
  427. const char MONTH_02 [] = "Luty";
  428. const char MONTH_03 [] = "Marzec";
  429. const char MONTH_04 [] = "Kwiecien";
  430. const char MONTH_05 [] = "Maj";
  431. const char MONTH_06 [] = "Czerwiec";
  432. const char MONTH_07 [] = "Lipiec";
  433. const char MONTH_08 [] = "Sierpien";
  434. const char MONTH_09 [] = "Wrzesien";
  435. const char MONTH_10 [] = "Pazdziernik";
  436. const char MONTH_11 [] = "Listopad";
  437. const char MONTH_12 [] = "Grudzien";
  438. #endif
  439.  
  440. // --- ENGLISH MONTH is LANGUAGE is true --- angielskie miesiące jeśli makro LANGUAGE jest TRUE -------------------------- //
  441.  
  442. #if ENGLISH
  443. const char MONTH_00 [] = "No Month";
  444. const char MONTH_01 [] = "January";
  445. const char MONTH_02 [] = "February";
  446. const char MONTH_03 [] = "March";
  447. const char MONTH_04 [] = "April";
  448. const char MONTH_05 [] = "May";
  449. const char MONTH_06 [] = "June";
  450. const char MONTH_07 [] = "July";
  451. const char MONTH_08 [] = "August";
  452. const char MONTH_09 [] = "September";
  453. const char MONTH_10 [] = "October";
  454. const char MONTH_11 [] = "November";
  455. const char MONTH_12 [] = "December";
  456. #endif
  457.  
  458. const char* const MONTH [] = {
  459. MONTH_00, MONTH_01, MONTH_02, MONTH_03, MONTH_04, MONTH_05, MONTH_06,
  460. MONTH_07, MONTH_08, MONTH_09, MONTH_10, MONTH_11, MONTH_12
  461. };
  462.  
  463. // ---------------------------------------------------------------------------------------------------------------- //
  464. // --- klasa Matryca --- //
  465. // ---------------------------------------------------------------------------------------------------------------- //
  466.  
  467. class Matryca
  468. {
  469. // -------------------------------------- //
  470. // --- zmienne i funkcje prywatne ------- //
  471. // -------------------------------------- //
  472.  
  473. private:
  474.  
  475. // -------------------------------------- //
  476. // --- adres obiektu MD_Parola ---------- //
  477. // -------------------------------------- //
  478.  
  479. MD_Parola &P;
  480.  
  481. // -------------------------------------- //
  482. // --- zmienne prywatne klasy Matryca --- //
  483. // -------------------------------------- //
  484.  
  485. uint8_t SpriteSize = 0; // rozmiar tablicy z duszkami
  486. uint8_t EffectSize = 0; // rozmiar tablicy z efektami
  487. uint8_t MaxMsgSize = 0; // rozmiar tablicy z wiadomosciami
  488. uint8_t MaxDaySize = 0; // rozmiar tablicy z dniami tygodnia
  489. uint8_t MaxMonthSize = 0; // rozmiar tablicy z miesiacami
  490. char LongDate[50]; // bufor : długa data
  491. char ShortDate[50]; // bufor : krótka data
  492. char ShortTime[20]; // bufor : krotki czas
  493. char Temperatura[30]; // bufor : temperatura st.C
  494. char Cisnienie[30]; // bufor : cisnienie hPa
  495. char Wilgotnosc[30]; // bufor : wilgotnosc %HG
  496. char Wiatr[30]; // bufor : predkosc wiatru km/h
  497.  
  498. // -------------------------------------- //
  499. // --- zmienne i metody prywatne -------- //
  500. // -------------------------------------- //
  501.  
  502. public:
  503.  
  504. // ------------------------------------------------------------------------------ //
  505. // --- konstruktor -------------------------------------------------------------- //
  506. // ------------------------------------------------------------------------------ //
  507.  
  508. Matryca(MD_Parola & adrP) : P ( adrP ) { }
  509.  
  510. // ------------------------------------------------------------------------------ //
  511. // --- setup -------------------------------------------------------------------- //
  512. // ------------------------------------------------------------------------------ //
  513.  
  514. void Setup()
  515. {
  516. // zapisz do zmiennych max. rozmiar tablicy
  517. // --------------------------------------------------------------------------- //
  518. SpriteSize = ARRAY_SIZE ( sprite ); // ustal rozmiar tablicy sprite
  519. EffectSize = ARRAY_SIZE ( efekt ); // ustal rozmiar tablicy effect
  520. MaxMsgSize = ARRAY_SIZE ( MSG ); // ustal rozmiar tablicy MSG
  521. MaxDaySize = ARRAY_SIZE ( DAY ); // ustal rozmiar tablicy DAY
  522. MaxMonthSize = ARRAY_SIZE ( MONTH ); // ustal rozmiar tablicy MONTH
  523. // --------------------------------------------------------------------------- //
  524. for (uint8_t i=0; i<EffectSize; i++)
  525. {
  526. efekt[i].speed *= P.getSpeed();
  527. efekt[i].pause *= 500;
  528. }
  529. // --------------------------------------------------------------------------- //
  530. // jeśli TERMINAL włączony
  531. #if TERMINAL
  532. Serial.println("SETUP");
  533. Serial.print("class Matryca -> Setup() -> Rozmiar tablicy /SPRITE/ : ");
  534. Serial.println( SpriteSize );
  535. Serial.print("class Matryca -> Setup() -> Rozmiar tablicy/EFFECT/ : ");
  536. Serial.println( EffectSize );
  537. Serial.print("class Matryca -> Setup() -> Rozmiar tablicy /DAY/ : ");
  538. Serial.println( MaxDaySize );
  539. Serial.print("class Matryca -> Setup() -> Rozmiar tablicy /MONTH/ : ");
  540. Serial.println( MaxMonthSize );
  541. Serial.print("class Matryca -> Setup() -> Rozmiar tablicy /MSG/ : ");
  542. Serial.println( MaxMsgSize );
  543. #endif
  544. }
  545.  
  546. // ------------------------------------------------------------------------------ //
  547. // --- PRIVATE METHOD --- METODY PRYWATNE --- DEKLARACJE ------------------------ //
  548. // ------------------------------------------------------------------------------ //
  549.  
  550.  
  551. // ------------------------------------------------------------------------------ //
  552. // --- PUBLIC METHOD --- METODY PUBLICZNE --- DEKLARACJE ------------------------ //
  553. // ------------------------------------------------------------------------------ //
  554.  
  555. void SpriteDemo(); // demo z duszkami
  556. void EffectDemo(); // demo z efektami
  557. void RandomDemo(); // demo : duszki lub efekty
  558. void ShowLongDate(); // wyswietl dluga date
  559. void ShowShortDate(); // wyswietl krotka date
  560. void ShowShortTime(); // pokaz czas - wersja Short
  561. void Date2Char(uint8_t day_of_week, uint8_t day, uint8_t month, uint16_t year);
  562. void Time2Char(uint8_t Godzina, uint8_t Minuta, uint8_t Sekunda);
  563. void Temp2Char( double temperatura, int cisnienie, int wilgotnosc, int wiatr);
  564. void ShowTemperature();
  565. void ShowPressure();
  566. void ShowHumidity();
  567. void ShowWind();
  568. };
  569.  
  570. // --------------------------------------------------------------------------------------------------- //
  571. // --- PRIVATE METHOD --- METODY PRYWATNE ------------------------------------------------------------ //
  572. // --------------------------------------------------------------------------------------------------- //
  573.  
  574. // --------------------------------------------------------------------------------------------------- //
  575. // --- PUBLIC METHOD --- METODY PUBLICZNE ------------------------------------------------------------ //
  576. // --------------------------------------------------------------------------------------------------- //
  577. //
  578. // void Matryca::SpriteDemo(); // demo z duszkami, napisy z listy MSG[]
  579. // void Matryca::EffectDemo(); // demo z efektami, napisy z listy MSG[]
  580. // void Matryca::RandomDemo(); // demo losowe (duszki, efekty)
  581. // void Matryca::ShowLongDate(); // pokazuje długą datę - scroll w lewo
  582. // void Matryca::ShowShortDate(); // pokazuje krótką datę - scroll w prawo
  583. // void Matryca::ShowShortTime(); // pokazuje czas - efekt losowy
  584. // void Matryca::Date2Char(); // buduje bufor char ShortDate i LongDate
  585. // void Matryca::Time2Char(); // buduje bufor char ShortTime
  586. // void Matryca::Temp2Char(); // buduje bufory char: temp, wilg, cisn, wiatr
  587. // void Matryca::ShowTemperature(); // pokaz temperature st.C - scroll w lewo
  588. // void Matryca::ShowPressure(); // poaz cisnienie atmosferyczne - scrool w lewo
  589. // void Matryca::ShowHumidity(); // pokaz wilgotnosc powietrza - scrool w lewo
  590. // void Matryca::ShowWind(); // pokaz predkosc wiatru -scrool w lewo
  591. //
  592. // --------------------------------------------------------------------------------------------------- //
  593. // --- Demo z duszkami - wykorzystuje napisy z tablicy MSG ------------------------------------------- //
  594. // --------------------------------------------------------------------------------------------------- //
  595. void Matryca::SpriteDemo() //
  596. { //
  597. if (P.displayAnimate()) //
  598. { //
  599. uint8_t curEFX = ESP8266TrueRandom.random(0, SpriteSize - 1); // wylosuj duszka ---------- //
  600. uint8_t curMSG = ESP8266TrueRandom.random(0, MaxMsgSize - 1); // wylosuj napis ----------- //
  601. //
  602. P.setSpriteData(sprite[curEFX].data,sprite[curEFX].width,sprite[curEFX].frames, // wejście duszka
  603. sprite[curEFX].data,sprite[curEFX].width,sprite[curEFX].frames); // wyjście duszka
  604. //
  605. P.displayText(MSG[curMSG], PA_CENTER, 20, 100, PA_SPRITE, PA_SPRITE); //
  606. //
  607. #if TERMINAL //
  608. Serial.print("class Matryca -> SpriteDemo -> Wyswietlam : "); //
  609. Serial.println(MSG[curMSG]); //
  610. #endif //
  611. } //
  612. } //
  613. // --------------------------------------------------------------------------------------------------- //
  614. // --- Demo z efektami - wykorzystuje napisy z tablicy MSG ------------------------------------------- //
  615. // --------------------------------------------------------------------------------------------------- //
  616. void Matryca::EffectDemo() //
  617. { //
  618. if(P.displayAnimate()) //
  619. { //
  620. uint8_t curEFX = ESP8266TrueRandom.random(0, EffectSize - 1); // wylosuj efekt ----------- //
  621. uint8_t curMSG = ESP8266TrueRandom.random(0, MaxMsgSize - 1); // wylosuj napis ----------- //
  622. //
  623. P.displayText(MSG[curMSG], PA_CENTER, efekt[curEFX].speed, efekt[curEFX].pause, //
  624. efekt[curEFX].effect, efekt[curEFX].effect); //
  625. #if TERMINAL //
  626. Serial.print("class Matryca -> EffectDemo -> Wyswietlam : "); //
  627. Serial.println(MSG[curMSG]); //
  628. #endif //
  629. } //
  630. } //
  631. // --------------------------------------------------------------------------------------------------- //
  632. // D E M O R A N D O M - S P R I T E O R E F F E C T //
  633. // --------------------------------------------------------------------------------------------------- //
  634. void Matryca::RandomDemo() //
  635. { //
  636. switch ( ESP8266TrueRandom.random(0,13) ) // wylosuj demo ------------- //
  637. { //
  638. case 0 : EffectDemo(); break; //
  639. case 1 : SpriteDemo(); break; //
  640. case 2 : ShowLongDate(); break;
  641. case 3 : ShowShortDate(); break;
  642. case 4 : ShowShortTime(); break;
  643. case 5 : ShowTemperature(); break;
  644. case 6 : ShowPressure(); break;
  645. case 7 : ShowHumidity(); break;
  646. case 8 : ShowWind(); break;
  647. case 9 : EffectDemo(); break;
  648. case 10 : SpriteDemo(); break;
  649. case 11 : ShowWind(); break;
  650. case 12 : ShowPressure(); break;
  651. default : break; //
  652. } //
  653. } //
  654. // --------------------------------------------------------------------------------------------------- //
  655. // S H O W L O N G D A T E //
  656. // --------------------------------------------------------------------------------------------------- //
  657. void Matryca::ShowLongDate() //
  658. { //
  659. if(P.displayAnimate()) //
  660. { //
  661. P.displayText(LongDate, PA_CENTER, 20, 0, efekt[3].effect, efekt[3].effect); //
  662. #if TERMINAL //
  663. Serial.print("class Matryca -> ShowLongDate -> Wyswietlam : "); //
  664. Serial.println(LongDate); //
  665. #endif //
  666. } //
  667. } //
  668. // --------------------------------------------------------------------------------------------------- //
  669. // S H O W S H O R T D A T E //
  670. // --------------------------------------------------------------------------------------------------- //
  671. void Matryca::ShowShortDate() //
  672. { //
  673. if(P.displayAnimate()) //
  674. { //
  675. P.displayText(ShortDate, PA_CENTER, 20, 0, efekt[3].effect, efekt[3].effect); //
  676. #if TERMINAL //
  677. Serial.print("class Matryca -> ShowShortDate -> Wyswietlam : "); //
  678. Serial.println(ShortDate); //
  679. #endif //
  680. } //
  681. } //
  682. // --------------------------------------------------------------------------------------------------- //
  683. // S H O W S H O R T T I M E //
  684. // --------------------------------------------------------------------------------------------------- //
  685. void Matryca::ShowShortTime() //
  686. { //
  687. if(P.displayAnimate()) //
  688. { //
  689. uint8_t curEFX = ESP8266TrueRandom.random(0, EffectSize - 1); // wylosuj efekt ----------- //
  690. //
  691. P.displayText(ShortTime, PA_CENTER, efekt[curEFX].speed, efekt[curEFX].pause, //
  692. efekt[curEFX].effect, efekt[curEFX].effect); //
  693. #if TERMINAL //
  694. Serial.print("class Matryca -> ShowShortTime -> Wyswietlam : "); //
  695. Serial.println(ShortTime); //
  696. #endif //
  697. } //
  698. } //
  699. // --------------------------------------------------------------------------------------------------- //
  700. // D A T E 2 C H A R --- buduje bufory: ShortDate, LongDate --- data z serwera NTP //
  701. // --------------------------------------------------------------------------------------------------- //
  702. void Matryca::Date2Char(uint8_t day_of_week, uint8_t day, uint8_t month, uint16_t year) //
  703. { //
  704. // przygotuj długą datę do wyświetlenia i zapisz ją w buforze char LongDate //
  705. String ldate = String(DAY[day_of_week]) + " " + String(day) + " " //
  706. + String(MONTH[month]) + " " + String(year); //
  707. //
  708. int str_len = ldate.length() + 1; // oblicz dlugosc STRING ldate --- //
  709. ldate.toCharArray(LongDate, str_len) ; // kopiuj STRING do CHAR --------- //
  710. //
  711. // przygotuj krótką datę do wyświetlenia i zapisz ją w buforze char ShortDate //
  712. String sdate = String(day) + " " + String(MONTH[month]) + " " + String(year); //
  713. str_len = sdate.length() + 1; //
  714. sdate.toCharArray(ShortDate, str_len); //
  715. //
  716. #if TERMINAL //
  717. Serial.println("class Matryca -> Date2Char -> Zbudowano bufory: LongDate i ShortDate "); //
  718. #endif //
  719. } //
  720. // --------------------------------------------------------------------------------------------------- //
  721. // T I M E 2 C H A R --- buduje bufory: ShortTime --- czas z serwera NTP //
  722. // --------------------------------------------------------------------------------------------------- //
  723. void Matryca::Time2Char(uint8_t Godzina, uint8_t Minuta, uint8_t Sekunda) //
  724. { //
  725. // przygotuj krótki czas do wyświetlenia i zapisz ją w buforze char ShortTime //
  726. String stime = "Czas: "; //
  727. if(Godzina < 10) stime += "0"; stime += String(Godzina) + ":"; //
  728. if(Minuta < 10) stime += "0"; stime += String(Minuta); //
  729. int str_len = stime.length() + 1; //
  730. stime.toCharArray(ShortTime, str_len); //
  731. //
  732. #if TERMINAL //
  733. Serial.println("class Matryca -> Time2Char -> Zbudowano bufor: ShortTime "); //
  734. #endif //
  735. } //
  736. // --------------------------------------------------------------------------------------------------- //
  737. void Matryca::Temp2Char
  738. (double temperatura, int cisnienie, int wilgotnosc, int wiatr)
  739. {
  740. String temp;
  741. int str_len = 0;
  742. // --- temperatura do bufora Temperatura ------------------------- //
  743. //temp.clear();
  744. temp = "Temperatura : " + String(temperatura) + " st.C";
  745. str_len = temp.length() + 1;
  746. temp.toCharArray(Temperatura, str_len);
  747. // --- cisnienie do bufora Cisnienie ----------------------------- //
  748. temp.clear();
  749. temp = "Cisnienie : " + String(cisnienie) + " hPa";
  750. str_len = temp.length() + 1;
  751. temp.toCharArray(Cisnienie, str_len);
  752. // --- wilgotnosc do bufora Wilgornosc --------------------------- //
  753. temp.clear();
  754. temp = "Wilgotnosc : " + String(wilgotnosc) + " % ";
  755. str_len = temp.length() + 1;
  756. temp.toCharArray(Wilgotnosc, str_len);
  757. // --- predkosc wiatru do bufora Wiatr -------------------------- //
  758. temp.clear();
  759. temp = "Predkosc wiatru: " + String(wiatr) + " km/h ";
  760. str_len = temp.length() + 1;
  761. temp.toCharArray(Wiatr, str_len);
  762. // -------------------------------------------------------------- //
  763. temp.clear();
  764. #if TERMINAL //
  765. Serial.println("class Matryca -> Temp2Char -> Zbudowano bufory pogodowe ! "); //
  766. #endif //
  767. }
  768. // --------------------------------------------------------------------------------------------------- //
  769. // S H O W T E M P E R A T U R E //
  770. // --------------------------------------------------------------------------------------------------- //
  771. void Matryca::ShowTemperature() //
  772. { //
  773. if(P.displayAnimate()) //
  774. { //
  775. P.displayText(Temperatura, PA_CENTER, 20, 0, efekt[3].effect, efekt[3].effect); //
  776. #if TERMINAL //
  777. Serial.print("class Matryca -> ShowTemperature -> Wyswietlam : "); //
  778. Serial.println(Temperatura); //
  779. #endif //
  780. } //
  781. } //
  782. // --------------------------------------------------------------------------------------------------- //
  783. // S H O W P R E S S U R E //
  784. // --------------------------------------------------------------------------------------------------- //
  785. void Matryca::ShowPressure() //
  786. { //
  787. if(P.displayAnimate()) //
  788. { //
  789. P.displayText(Cisnienie, PA_CENTER, 20, 0, efekt[3].effect, efekt[3].effect); //
  790. #if TERMINAL //
  791. Serial.print("class Matryca -> ShowPressure -> Wyswietlam : "); //
  792. Serial.println(Cisnienie); //
  793. #endif //
  794. } //
  795. } //
  796. // --------------------------------------------------------------------------------------------------- //
  797. // S H O W H U M I D I T Y //
  798. // --------------------------------------------------------------------------------------------------- //
  799. void Matryca::ShowHumidity() //
  800. { //
  801. if(P.displayAnimate()) //
  802. { //
  803. P.displayText(Wilgotnosc, PA_CENTER, 20, 0, efekt[3].effect, efekt[3].effect); //
  804. #if TERMINAL //
  805. Serial.print("class Matryca -> ShowHumidity -> Wyswietlam : "); //
  806. Serial.println(Wilgotnosc); //
  807. #endif //
  808. } //
  809. } //
  810. // --------------------------------------------------------------------------------------------------- //
  811. // S H O W W I N D //
  812. // --------------------------------------------------------------------------------------------------- //
  813. void Matryca::ShowWind() //
  814. { //
  815. if(P.displayAnimate()) //
  816. { //
  817. P.displayText(Wiatr, PA_CENTER, 20, 0, efekt[3].effect, efekt[3].effect); //
  818. #if TERMINAL //
  819. Serial.print("class Matryca -> ShowHumidity -> Wyswietlam : "); //
  820. Serial.println(Wiatr); //
  821. #endif //
  822. } //
  823. } //
  824. // --------------------------------------------------------------------------------------------------- //
  825.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement