GxEPD2_RefreshTests.ino 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. // Display Library example for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
  2. // Requires HW SPI and Adafruit_GFX. Caution: these e-papers require 3.3V supply AND data lines!
  3. //
  4. // Display Library based on Demo Example from Good Display: http://www.e-paper-display.com/download_list/downloadcategoryid=34&isMode=false.html
  5. //
  6. // Author: Jean-Marc Zingg
  7. //
  8. // Version: see library.properties
  9. //
  10. // Library: https://github.com/ZinggJM/GxEPD2
  11. #include <GxEPD2_BW.h>
  12. #include <GxEPD2_3C.h>
  13. #include "Open_Sans_ExtraBold_120.h"
  14. #if defined (ESP8266)
  15. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  16. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  17. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDE0213B1, phased out
  18. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0213B72
  19. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0213B73
  20. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0213I5F
  21. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  22. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW029T5
  23. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  24. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  25. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  26. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  27. // can use only half buffer size
  28. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  29. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  30. //GxEPD2_BW < GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT / 2 > display(GxEPD2_750_T7(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW075T7 800x480
  31. // 3-color e-papers
  32. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  33. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  34. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  35. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  36. // can use only half buffer size
  37. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  38. // can use only quarter buffer size
  39. //GxEPD2_3C < GxEPD2_583c, GxEPD2_583c::HEIGHT / 4 > display(GxEPD2_583c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  40. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  41. //GxEPD2_3C < GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT / 4 > display(GxEPD2_750c_Z08(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW075Z08 800x480
  42. // grey levels parallel IF e-papers on Waveshare e-Paper IT8951 Driver HAT
  43. // HRDY -> 4, RST -> 2, CS -> SS(15), SCK -> SCK(14), MOSI -> MOSI(D7(13)), MISO -> MISO(D6(12)), GND -> GND, 5V -> 5V
  44. // note: 5V supply needs to be exact and strong; 5V pin of USB powered Wemos D1 mini doesn't work!
  45. //GxEPD2_BW<GxEPD2_it60, GxEPD2_it60::HEIGHT / 8> display(GxEPD2_it60(/*CS=5*/ SS, /*DC=*/ 0, /*RST=*/ 2, /*BUSY=*/ 4));
  46. // ***** for mapping of Waveshare e-Paper ESP8266 Driver Board *****
  47. // select one , can use full buffer size (full HEIGHT)
  48. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  49. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDE0213B1, phased out
  50. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEH0213B72
  51. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEH0213B73
  52. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW0213I5F
  53. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  54. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW029T5
  55. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  56. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  57. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  58. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  59. // can use only half buffer size
  60. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  61. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  62. //GxEPD2_BW < GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT / 2 > display(GxEPD2_750_T7(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW075T7 800x480
  63. // 3-color e-papers
  64. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  65. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  66. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  67. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  68. // can use only half buffer size
  69. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  70. // can use only quarter buffer size
  71. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  72. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  73. //GxEPD2_3C<GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT / 4> display(GxEPD2_750c_Z08(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW075Z08 800x480
  74. #endif
  75. #if defined(ESP32)
  76. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  77. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  78. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDE0213B1, phased out
  79. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B72
  80. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B73
  81. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0213I5F
  82. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  83. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW029T5
  84. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  85. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  86. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  87. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  88. //GxEPD2_BW<GxEPD2_583, GxEPD2_583::HEIGHT> display(GxEPD2_583(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  89. //GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  90. // 3-color e-papers
  91. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  92. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  93. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  94. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  95. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT> display(GxEPD2_420c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  96. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT> display(GxEPD2_583c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  97. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT> display(GxEPD2_750c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  98. //GxEPD2_3C<GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT> display(GxEPD2_750c_Z08(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW075Z08 800x480
  99. // grey levels parallel IF e-papers on Waveshare e-Paper IT8951 Driver HAT
  100. // HRDY -> 4, RST -> 16, CS -> SS(5), SCK -> SCK(18), MOSI -> MOSI(23), MISO -> MISO(19), GND -> GND, 5V -> 5V
  101. // note: 5V supply needs to be exact and strong; 5V over diode from USB (e.g. Wemos D1 mini) doesn't work!
  102. //GxEPD2_BW<GxEPD2_it60, GxEPD2_it60::HEIGHT> display(GxEPD2_it60(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  103. #endif
  104. //const uint32_t partial_update_period_s = 2;
  105. const uint32_t partial_update_period_s = 60;
  106. const uint32_t full_update_period_s = 1 * 60 * 60;
  107. const uint32_t speed_up_factor = 20; // for simulation
  108. const uint32_t millis_per_second = 1000 / speed_up_factor;
  109. uint32_t start_time;
  110. uint32_t next_time;
  111. uint32_t previous_time;
  112. uint32_t previous_full_update;
  113. uint32_t total_seconds = 0;
  114. uint32_t seconds, minutes, hours, days;
  115. void setup()
  116. {
  117. Serial.begin(115200);
  118. Serial.println();
  119. Serial.println("setup");
  120. delay(100);
  121. display.init(115200);
  122. // cleanup
  123. for (int i = 0; i < 1; i++)
  124. {
  125. full_black();
  126. delay(500);
  127. full_white();
  128. delay(500);
  129. }
  130. // stripes test
  131. for (int i = 0; i < 1; i++)
  132. {
  133. horizontal_stripes(8);
  134. delay(1000);
  135. vertical_stripes(8);
  136. delay(3000);
  137. }
  138. full_white();
  139. delay(1000);
  140. // clock simulation test, for limited length
  141. for (int i = 0; i < 20; i++)
  142. {
  143. clock_test();
  144. }
  145. delay(3000);
  146. full_white();
  147. delay(1000);
  148. display.powerOff();
  149. delay(1000);
  150. start_time = next_time = previous_time = previous_full_update = millis();
  151. Serial.println("setup done");
  152. }
  153. void loop()
  154. {
  155. // uncomment for continuous clock simulation test
  156. //clock_test();
  157. }
  158. void full_white()
  159. {
  160. display.setFullWindow();
  161. display.firstPage();
  162. do
  163. {
  164. display.fillScreen(GxEPD_WHITE);
  165. }
  166. while (display.nextPage());
  167. }
  168. void full_black()
  169. {
  170. display.setFullWindow();
  171. display.firstPage();
  172. do
  173. {
  174. display.fillScreen(GxEPD_BLACK);
  175. }
  176. while (display.nextPage());
  177. }
  178. void partial_white()
  179. {
  180. display.setPartialWindow(0, 0, display.width(), display.height());
  181. display.firstPage();
  182. do
  183. {
  184. display.fillScreen(GxEPD_WHITE);
  185. }
  186. while (display.nextPage());
  187. }
  188. void partial_black()
  189. {
  190. display.setPartialWindow(0, 0, display.width(), display.height());
  191. display.firstPage();
  192. do
  193. {
  194. display.fillScreen(GxEPD_BLACK);
  195. }
  196. while (display.nextPage());
  197. }
  198. void horizontal_stripes(uint16_t nr)
  199. {
  200. uint16_t h = display.height() / nr;
  201. display.setPartialWindow(0, 0, display.width(), display.height());
  202. display.firstPage();
  203. do
  204. {
  205. uint16_t y = 0;
  206. do
  207. {
  208. display.fillRect(0, y, display.width(), h, GxEPD_BLACK);
  209. y += h;
  210. if (y >= display.height()) break;
  211. display.fillRect(0, y, display.width(), h, GxEPD_WHITE);
  212. y += h;
  213. } while (y < display.height());
  214. }
  215. while (display.nextPage());
  216. }
  217. void vertical_stripes(uint16_t nr)
  218. {
  219. uint16_t w = display.width() / nr;
  220. display.setPartialWindow(0, 0, display.width(), display.height());
  221. display.firstPage();
  222. do
  223. {
  224. uint16_t x = 0;
  225. do
  226. {
  227. display.fillRect(x, 0, w, display.height(), GxEPD_BLACK);
  228. x += w;
  229. if (x >= display.width()) break;
  230. display.fillRect(x, 0, w, display.height(), GxEPD_WHITE);
  231. x += w;
  232. } while (x < display.width());
  233. }
  234. while (display.nextPage());
  235. }
  236. void clock_test()
  237. {
  238. uint32_t actual = millis();
  239. while (actual < next_time)
  240. {
  241. // the "BlinkWithoutDelay" method works also for overflowed millis
  242. if ((actual - previous_time) > (partial_update_period_s * 1000))
  243. {
  244. //Serial.print(actual - previous_time); Serial.print(" > "); Serial.println(partial_update_period_s * 1000);
  245. break;
  246. }
  247. delay(100);
  248. actual = millis();
  249. }
  250. if ((actual - previous_full_update) > full_update_period_s * millis_per_second)
  251. {
  252. //display.clearScreen();
  253. previous_full_update = actual;
  254. }
  255. previous_time = actual;
  256. next_time += uint32_t(partial_update_period_s * millis_per_second);
  257. total_seconds += partial_update_period_s;
  258. seconds = total_seconds % 60;
  259. minutes = (total_seconds / 60) % 60;
  260. hours = (total_seconds / 3600) % 24;
  261. days = (total_seconds / 3600) / 24;
  262. if ((display.width() >= 400) && (display.height() >= 300))
  263. {
  264. showDays();
  265. showTime();
  266. }
  267. else showMinutes();
  268. display.powerOff();
  269. }
  270. String str02(uint32_t v)
  271. {
  272. return (v < 10 ? String(0) + String(v) : String(v));
  273. }
  274. void showMinutes()
  275. {
  276. static int16_t bbx = 400;
  277. static int16_t bby = 300;
  278. static uint16_t bbw = 0;
  279. static uint16_t bbh = 0;
  280. //Serial.println("showMinutes");
  281. String str = str02(minutes);
  282. display.setRotation(display.epd2.WIDTH > display.epd2.HEIGHT ? 0 : 1);
  283. display.setFont(&Open_Sans_ExtraBold_120);
  284. display.setTextColor(GxEPD_BLACK);
  285. int16_t tbx, tby; uint16_t tbw, tbh;
  286. display.getTextBounds(str, 0, 0, &tbx, &tby, &tbw, &tbh);
  287. // place the bounding box, cover any previous ones
  288. int16_t tx = max(0, ((display.width() - tbw) / 2));
  289. int16_t ty = max(0, ((display.height() - tbh) / 2));
  290. bbx = min(bbx, tx);
  291. bby = min(bby, ty);
  292. bbw = max(bbw, tbw);
  293. bbh = max(bbh, tbh);
  294. // calculate the cursor
  295. int16_t x = bbx - tbx;
  296. int16_t y = bby - tby;
  297. display.setPartialWindow(bbx, bby, bbw, bbh);
  298. display.firstPage();
  299. do
  300. {
  301. display.fillScreen(GxEPD_WHITE);
  302. //display.drawRect(bbx, bby, bbw, bbh, GxEPD_BLACK);
  303. display.setCursor(x, y);
  304. display.print(str);
  305. }
  306. while (display.nextPage());
  307. delay(1000);
  308. //Serial.println("showMinutes done");
  309. }
  310. void showDays()
  311. {
  312. static int16_t bbx = 400;
  313. static int16_t bby = 300;
  314. static uint16_t bbw = 0;
  315. static uint16_t bbh = 0;
  316. //Serial.println("showDays");
  317. String str(days); str += " days";
  318. display.setRotation(0);
  319. display.setFont(&Open_Sans_ExtraBold_120);
  320. display.setTextColor(GxEPD_BLACK);
  321. int16_t tbx, tby; uint16_t tbw, tbh;
  322. display.getTextBounds(str, 0, 0, &tbx, &tby, &tbw, &tbh);
  323. // place the bounding box
  324. int16_t tx = max(0, ((display.width() - tbw) / 2));
  325. int16_t ty = max(0, (display.height() / 4 - tbh / 2));
  326. bbx = min(bbx, tx);
  327. bby = min(bby, ty);
  328. bbw = max(bbw, tbw);
  329. bbh = max(bbh, tbh);
  330. // calculate the cursor
  331. uint16_t x = bbx - tbx;
  332. uint16_t y = bby - tby;
  333. display.setPartialWindow(bbx, bby, bbw, bbh);
  334. display.firstPage();
  335. do
  336. {
  337. display.fillScreen(GxEPD_WHITE);
  338. //display.drawRect(bbx, bby, bbw, bbh, GxEPD_BLACK);
  339. display.setCursor(x, y);
  340. display.print(str);
  341. }
  342. while (display.nextPage());
  343. delay(1000);
  344. //Serial.println("showDays done");
  345. }
  346. void showTime()
  347. {
  348. static int16_t bbx = 400;
  349. static int16_t bby = 300;
  350. static uint16_t bbw = 0;
  351. static uint16_t bbh = 0;
  352. //Serial.println("showTime");
  353. //String str = str02(minutes) + ":" + str02(seconds);
  354. String str = str02(hours) + ":" + str02(minutes);
  355. display.setRotation(0);
  356. display.setFont(&Open_Sans_ExtraBold_120);
  357. display.setTextColor(GxEPD_BLACK);
  358. int16_t tbx, tby; uint16_t tbw, tbh;
  359. display.getTextBounds(str, 0, 0, &tbx, &tby, &tbw, &tbh);
  360. // place the bounding box
  361. int16_t tx = max(0, ((display.width() - tbw) / 2));
  362. int16_t ty = max(0, (display.height() * 3 / 4 - tbh / 2));
  363. bbx = min(bbx, tx);
  364. bby = min(bby, ty);
  365. bbw = max(bbw, tbw);
  366. bbh = max(bbh, tbh);
  367. // calculate the cursor
  368. uint16_t x = bbx - tbx;
  369. uint16_t y = bby - tby;
  370. display.setPartialWindow(bbx, bby, bbw, bbh);
  371. display.firstPage();
  372. do
  373. {
  374. display.fillScreen(GxEPD_WHITE);
  375. //display.drawRect(bbx, bby, bbw, bbh, GxEPD_BLACK);
  376. display.setCursor(x, y);
  377. display.print(str);
  378. }
  379. while (display.nextPage());
  380. //Serial.println("showTime done");
  381. }