GxEPD2_RefreshTests.ino 20 KB

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