GxEPD2_Example.ino 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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. // based on Demo Example from Good Display: http://www.good-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. // Supporting Arduino Forum Topics:
  12. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  13. // Good Dispay ePaper for Arduino : https://forum.arduino.cc/index.php?topic=436411.0
  14. // mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
  15. // BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
  16. // mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
  17. // BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  18. // mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
  19. // NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
  20. // BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V
  21. // new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
  22. // BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
  23. // mapping suggestion for AVR, UNO, NANO etc.
  24. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11
  25. #include <GxEPD2_BW.h>
  26. #include <GxEPD2_3C.h>
  27. #include <Fonts/FreeMonoBold9pt7b.h>
  28. #if defined (ESP8266)
  29. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  30. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  31. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  32. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  33. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*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_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  38. // 3-color e-papers
  39. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  40. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  41. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  42. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  43. // can use only half buffer size
  44. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  45. // can use only quarter buffer size
  46. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  47. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  48. #endif
  49. #if defined(ESP32)
  50. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  51. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  52. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  53. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  54. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  55. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  56. //GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  57. // 3-color e-papers
  58. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  59. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  60. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  61. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  62. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT> display(GxEPD2_420c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  63. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT> display(GxEPD2_750c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  64. #endif
  65. #if defined(_BOARD_GENERIC_STM32F103C_H_)
  66. #define MAX_DISPAY_BUFFER_SIZE (400 * 300) // ~5k is a good compromise
  67. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH)
  68. // select one and adapt to your mapping
  69. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  70. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  71. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  72. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  73. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  74. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  75. // 3-color e-papers
  76. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  77. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  78. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  79. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  80. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  81. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  82. #endif
  83. #if defined(__AVR)
  84. #define MAX_DISPAY_BUFFER_SIZE 1000 // half of available RAM as a compromise
  85. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH)
  86. // select one and adapt to your mapping
  87. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  88. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  89. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  90. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  91. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  92. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  93. // 3-color e-papers
  94. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  95. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  96. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  97. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  98. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  99. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  100. #endif
  101. void setup()
  102. {
  103. Serial.begin(115200);
  104. Serial.println();
  105. Serial.println("setup");
  106. display.init();
  107. helloWorld();
  108. delay(1000);
  109. helloArduino();
  110. delay(1000);
  111. helloEpaper();
  112. delay(1000);
  113. showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
  114. delay(1000);
  115. drawBitmaps();
  116. if (display.epd2.hasPartialUpdate)
  117. {
  118. showPartialUpdate();
  119. delay(1000);
  120. } // else // on GDEW0154Z04 only full update available, doesn't look nice
  121. //drawCornerTest();
  122. //showBox(16, 16, 48, 32, false);
  123. //showBox(16, 56, 48, 32, true);
  124. display.powerOff();
  125. Serial.println("setup done");
  126. }
  127. void loop()
  128. {
  129. }
  130. void helloWorld()
  131. {
  132. //Serial.println("helloWorld");
  133. display.setRotation(1);
  134. display.setFont(&FreeMonoBold9pt7b);
  135. display.setTextColor(GxEPD_BLACK);
  136. uint16_t x = (display.width() - 160) / 2;
  137. uint16_t y = display.height() / 2;
  138. display.firstPage();
  139. do
  140. {
  141. display.fillScreen(GxEPD_WHITE);
  142. display.setCursor(x, y);
  143. display.println("Hello World!");
  144. }
  145. while (display.nextPage());
  146. //Serial.println("helloWorld done");
  147. }
  148. void helloArduino()
  149. {
  150. //Serial.println("helloArduino");
  151. display.setRotation(1);
  152. display.setFont(&FreeMonoBold9pt7b);
  153. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  154. uint16_t x = (display.width() - 160) / 2;
  155. uint16_t y = display.height() / 4;
  156. display.setPartialWindow(0, y - 14, display.width(), 20);
  157. display.firstPage();
  158. do
  159. {
  160. display.fillScreen(GxEPD_WHITE);
  161. display.setCursor(x, y);
  162. display.println("Hello Arduino!");
  163. }
  164. while (display.nextPage());
  165. delay(1000);
  166. //Serial.println("helloArduino done");
  167. }
  168. void helloEpaper()
  169. {
  170. //Serial.println("helloEpaper");
  171. display.setRotation(1);
  172. display.setFont(&FreeMonoBold9pt7b);
  173. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  174. uint16_t x = (display.width() - 160) / 2;
  175. uint16_t y = display.height() * 3 / 4;
  176. display.setPartialWindow(0, y - 14, display.width(), 20);
  177. display.firstPage();
  178. do
  179. {
  180. display.fillScreen(GxEPD_WHITE);
  181. display.setCursor(x, y);
  182. display.println("Hello E-Paper!");
  183. }
  184. while (display.nextPage());
  185. //Serial.println("helloEpaper done");
  186. }
  187. void showBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool partial)
  188. {
  189. //Serial.println("showBox");
  190. display.setRotation(1);
  191. if (partial)
  192. {
  193. display.setPartialWindow(x, y, w, h);
  194. }
  195. else
  196. {
  197. display.setFullWindow();
  198. }
  199. display.firstPage();
  200. do
  201. {
  202. display.fillScreen(GxEPD_WHITE);
  203. display.fillRect(x, y, w, h, GxEPD_BLACK);
  204. }
  205. while (display.nextPage());
  206. //Serial.println("showBox done");
  207. }
  208. void drawCornerTest()
  209. {
  210. display.setFullWindow();
  211. display.setFont(&FreeMonoBold9pt7b);
  212. display.setTextColor(GxEPD_BLACK);
  213. for (uint16_t r = 0; r <= 4; r++)
  214. {
  215. display.setRotation(r);
  216. display.firstPage();
  217. do
  218. {
  219. display.fillScreen(GxEPD_WHITE);
  220. display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
  221. display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
  222. display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
  223. display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
  224. display.setCursor(display.width() / 2, display.height() / 2);
  225. display.print(display.getRotation());
  226. }
  227. while (display.nextPage());
  228. delay(2000);
  229. }
  230. }
  231. void showFont(const char name[], const GFXfont* f)
  232. {
  233. display.setFullWindow();
  234. display.setRotation(0);
  235. display.setTextColor(GxEPD_BLACK);
  236. display.firstPage();
  237. do
  238. {
  239. drawFont(name, f);
  240. }
  241. while (display.nextPage());
  242. }
  243. void drawFont(const char name[], const GFXfont* f)
  244. {
  245. //display.setRotation(0);
  246. display.fillScreen(GxEPD_WHITE);
  247. display.setTextColor(GxEPD_BLACK);
  248. display.setFont(f);
  249. display.setCursor(0, 0);
  250. display.println();
  251. display.println(name);
  252. display.println(" !\"#$%&'()*+,-./");
  253. display.println("0123456789:;<=>?");
  254. display.println("@ABCDEFGHIJKLMNO");
  255. display.println("PQRSTUVWXYZ[\\]^_");
  256. if (display.epd2.hasColor)
  257. {
  258. display.setTextColor(GxEPD_RED);
  259. }
  260. display.println("`abcdefghijklmno");
  261. display.println("pqrstuvwxyz{|}~ ");
  262. }
  263. void showPartialUpdate()
  264. {
  265. // some useful background
  266. helloWorld();
  267. // use asymmetric values for test
  268. uint16_t box_x = 10;
  269. uint16_t box_y = 15;
  270. uint16_t box_w = 70;
  271. uint16_t box_h = 20;
  272. uint16_t cursor_y = box_y + box_h - 6;
  273. float value = 13.95;
  274. uint16_t incr = display.epd2.hasFastPartialUpdate ? 1 : 3;
  275. display.setFont(&FreeMonoBold9pt7b);
  276. display.setTextColor(GxEPD_BLACK);
  277. // show where the update box is
  278. for (uint16_t r = 0; r < 4; r++)
  279. {
  280. display.setRotation(r);
  281. display.setPartialWindow(box_x, box_y, box_w, box_h);
  282. display.firstPage();
  283. do
  284. {
  285. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_BLACK);
  286. //display.fillScreen(GxEPD_BLACK);
  287. }
  288. while (display.nextPage());
  289. delay(2000);
  290. display.firstPage();
  291. do
  292. {
  293. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  294. }
  295. while (display.nextPage());
  296. delay(1000);
  297. }
  298. //return;
  299. // show updates in the update box
  300. for (uint16_t r = 0; r < 4; r++)
  301. {
  302. display.setRotation(r);
  303. display.setPartialWindow(box_x, box_y, box_w, box_h);
  304. for (uint16_t i = 1; i <= 10; i += incr)
  305. {
  306. display.firstPage();
  307. do
  308. {
  309. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  310. display.setCursor(box_x, cursor_y);
  311. display.print(value * i, 2);
  312. }
  313. while (display.nextPage());
  314. delay(500);
  315. }
  316. delay(1000);
  317. display.firstPage();
  318. do
  319. {
  320. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  321. }
  322. while (display.nextPage());
  323. delay(1000);
  324. }
  325. }
  326. // comment out unused bitmaps to reduce code space used
  327. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  328. #include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  329. #include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  330. #include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  331. #include "bitmaps/Bitmaps400x300.h" // 4.2" b/w
  332. #include "bitmaps/Bitmaps640x384.h" // 7.5" b/w
  333. // 3-color
  334. #include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  335. #include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  336. #include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  337. #include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  338. #include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r
  339. void drawBitmaps()
  340. {
  341. display.setFullWindow();
  342. #ifdef _GxBitmaps128x250_H_
  343. drawBitmaps128x250();
  344. #endif
  345. #ifdef _GxBitmaps128x296_H_
  346. drawBitmaps128x296();
  347. #endif
  348. #ifdef _GxBitmaps176x264_H_
  349. drawBitmaps176x264();
  350. #endif
  351. #ifdef _GxBitmaps400x300_H_
  352. drawBitmaps400x300();
  353. #endif
  354. #ifdef _GxBitmaps640x384_H_
  355. drawBitmaps640x384();
  356. #endif
  357. // 3-color
  358. #ifdef _GxBitmaps3c104x212_H_
  359. drawBitmaps3c104x212();
  360. #endif
  361. #ifdef _GxBitmaps3c128x296_H_
  362. drawBitmaps3c128x296();
  363. #endif
  364. #ifdef _GxBitmaps3c176x264_H_
  365. drawBitmaps3c176x264();
  366. #endif
  367. #ifdef _GxBitmaps3c400x300_H_
  368. drawBitmaps3c400x300();
  369. #endif
  370. // show these after the specific bitmaps
  371. #ifdef _GxBitmaps200x200_H_
  372. drawBitmaps200x200();
  373. #endif
  374. // 3-color
  375. #ifdef _GxBitmaps3c200x200_H_
  376. drawBitmaps3c200x200();
  377. #endif
  378. }
  379. #ifdef _GxBitmaps200x200_H_
  380. void drawBitmaps200x200()
  381. {
  382. const unsigned char* bitmaps[] =
  383. {
  384. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  385. };
  386. if (display.epd2.panel == GxEPD2::GDEP015OC1)
  387. {
  388. bool m = display.mirror(true);
  389. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  390. {
  391. display.firstPage();
  392. do
  393. {
  394. display.fillScreen(GxEPD_WHITE);
  395. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  396. }
  397. while (display.nextPage());
  398. delay(2000);
  399. }
  400. display.mirror(m);
  401. }
  402. //else
  403. {
  404. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  405. display.clearScreen(); // use default for white
  406. uint16_t x = (display.epd2.WIDTH - 200) / 2;
  407. uint16_t y = (display.epd2.HEIGHT - 200) / 2;
  408. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  409. {
  410. display.drawImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  411. delay(2000);
  412. }
  413. }
  414. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  415. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  416. {
  417. int16_t x = -60;
  418. int16_t y = -60;
  419. for (uint16_t j = 0; j < 10; j++)
  420. {
  421. display.writeScreenBuffer(); // use default for white
  422. display.writeImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  423. display.refresh(true);
  424. delay(2000);
  425. x += 40;
  426. y += 40;
  427. if ((x >= display.epd2.WIDTH) || (y >= display.epd2.HEIGHT)) break;
  428. }
  429. if (!display.epd2.hasFastPartialUpdate) break; // comment out for full show
  430. break; // comment out for full show
  431. }
  432. display.writeScreenBuffer(); // use default for white
  433. display.writeImage(bitmaps[0], 0, 0, 200, 200, false, mirror_y, true);
  434. display.writeImage(bitmaps[0], display.epd2.WIDTH - 200, display.epd2.HEIGHT - 200, 200, 200, false, mirror_y, true);
  435. display.refresh(true);
  436. delay(2000);
  437. }
  438. #endif
  439. #ifdef _GxBitmaps128x250_H_
  440. void drawBitmaps128x250()
  441. {
  442. const unsigned char* bitmaps[] =
  443. {
  444. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  445. };
  446. if (display.epd2.panel == GxEPD2::GDE0213B1)
  447. {
  448. bool m = display.mirror(true);
  449. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  450. {
  451. display.firstPage();
  452. do
  453. {
  454. display.fillScreen(GxEPD_WHITE);
  455. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  456. }
  457. while (display.nextPage());
  458. delay(2000);
  459. }
  460. display.mirror(m);
  461. }
  462. }
  463. #endif
  464. #ifdef _GxBitmaps128x296_H_
  465. void drawBitmaps128x296()
  466. {
  467. const unsigned char* bitmaps[] =
  468. {
  469. Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
  470. };
  471. if (display.epd2.panel == GxEPD2::GDEH029A1)
  472. {
  473. bool m = display.mirror(true);
  474. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  475. {
  476. display.firstPage();
  477. do
  478. {
  479. display.fillScreen(GxEPD_WHITE);
  480. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  481. }
  482. while (display.nextPage());
  483. delay(2000);
  484. }
  485. display.mirror(m);
  486. }
  487. }
  488. #endif
  489. #ifdef _GxBitmaps176x264_H_
  490. void drawBitmaps176x264()
  491. {
  492. const unsigned char* bitmaps[] =
  493. {
  494. Bitmap176x264_1, Bitmap176x264_2
  495. };
  496. if (display.epd2.panel == GxEPD2::GDEW027W3)
  497. {
  498. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  499. {
  500. display.firstPage();
  501. do
  502. {
  503. display.fillScreen(GxEPD_WHITE);
  504. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  505. }
  506. while (display.nextPage());
  507. delay(2000);
  508. }
  509. }
  510. }
  511. #endif
  512. #ifdef _GxBitmaps400x300_H_
  513. void drawBitmaps400x300()
  514. {
  515. const unsigned char* bitmaps[] =
  516. {
  517. Bitmap400x300_1, Bitmap400x300_2
  518. };
  519. if (display.epd2.panel == GxEPD2::GDEW042T2)
  520. {
  521. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  522. {
  523. display.firstPage();
  524. do
  525. {
  526. display.fillScreen(GxEPD_WHITE);
  527. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  528. }
  529. while (display.nextPage());
  530. delay(2000);
  531. }
  532. }
  533. }
  534. #endif
  535. #ifdef _GxBitmaps640x384_H_
  536. void drawBitmaps640x384()
  537. {
  538. const unsigned char* bitmaps[] =
  539. {
  540. Bitmap640x384_1, Bitmap640x384_2
  541. };
  542. if (display.epd2.panel == GxEPD2::GDEW075T8)
  543. {
  544. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  545. {
  546. display.firstPage();
  547. do
  548. {
  549. display.fillScreen(GxEPD_WHITE);
  550. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  551. }
  552. while (display.nextPage());
  553. delay(2000);
  554. }
  555. }
  556. }
  557. #endif
  558. struct bitmap_pair
  559. {
  560. const unsigned char* black;
  561. const unsigned char* red;
  562. };
  563. #ifdef _GxBitmaps3c200x200_H_
  564. void drawBitmaps3c200x200()
  565. {
  566. bitmap_pair bitmap_pairs[] =
  567. {
  568. //{Bitmap3c200x200_black, Bitmap3c200x200_red},
  569. {WS_Bitmap3c200x200_black, WS_Bitmap3c200x200_red}
  570. };
  571. if (display.epd2.panel == GxEPD2::GDEW0154Z04)
  572. {
  573. display.firstPage();
  574. do
  575. {
  576. display.fillScreen(GxEPD_WHITE);
  577. // Bitmap3c200x200_black has 2 bits per pixel
  578. // taken from Adafruit_GFX.cpp, modified
  579. int16_t byteWidth = (display.epd2.WIDTH + 7) / 8; // Bitmap scanline pad = whole byte
  580. uint8_t byte = 0;
  581. for (int16_t j = 0; j < display.epd2.HEIGHT; j++)
  582. {
  583. for (int16_t i = 0; i < display.epd2.WIDTH; i++)
  584. {
  585. if (i & 3) byte <<= 2;
  586. else
  587. {
  588. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  589. byte = pgm_read_byte(&Bitmap3c200x200_black[j * byteWidth * 2 + i / 4]);
  590. #else
  591. byte = Bitmap3c200x200_black[j * byteWidth * 2 + i / 4];
  592. #endif
  593. }
  594. if (!(byte & 0x80))
  595. {
  596. display.drawPixel(i, j, GxEPD_BLACK);
  597. }
  598. }
  599. }
  600. display.drawInvertedBitmap(0, 0, Bitmap3c200x200_red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  601. }
  602. while (display.nextPage());
  603. delay(2000);
  604. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  605. {
  606. display.firstPage();
  607. do
  608. {
  609. display.fillScreen(GxEPD_WHITE);
  610. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  611. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  612. }
  613. while (display.nextPage());
  614. delay(2000);
  615. }
  616. }
  617. if (display.epd2.hasColor)
  618. {
  619. display.clearScreen(); // use default for white
  620. uint16_t x = (display.epd2.WIDTH - 200) / 2;
  621. uint16_t y = (display.epd2.HEIGHT - 200) / 2;
  622. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  623. {
  624. display.drawImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  625. delay(2000);
  626. }
  627. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  628. {
  629. int16_t x = -60;
  630. int16_t y = -60;
  631. for (uint16_t j = 0; j < 10; j++)
  632. {
  633. display.writeScreenBuffer(); // use default for white
  634. display.writeImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  635. display.refresh();
  636. delay(2000);
  637. x += 40;
  638. y += 40;
  639. if ((x >= display.epd2.WIDTH) || (y >= display.epd2.HEIGHT)) break;
  640. }
  641. }
  642. display.writeScreenBuffer(); // use default for white
  643. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, 0, 0, 200, 200, false, false, true);
  644. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, display.epd2.WIDTH - 200, display.epd2.HEIGHT - 200, 200, 200, false, false, true);
  645. display.refresh();
  646. delay(2000);
  647. }
  648. }
  649. #endif
  650. #ifdef _GxBitmaps3c104x212_H_
  651. void drawBitmaps3c104x212()
  652. {
  653. bitmap_pair bitmap_pairs[] =
  654. {
  655. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  656. {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  657. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  658. };
  659. if (display.epd2.panel == GxEPD2::GDEW0213Z16)
  660. {
  661. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  662. {
  663. display.firstPage();
  664. do
  665. {
  666. display.fillScreen(GxEPD_WHITE);
  667. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  668. if (bitmap_pairs[i].red == WS_Bitmap3c104x212_red)
  669. {
  670. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  671. }
  672. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  673. }
  674. while (display.nextPage());
  675. delay(2000);
  676. }
  677. }
  678. }
  679. #endif
  680. #ifdef _GxBitmaps3c128x296_H_
  681. void drawBitmaps3c128x296()
  682. {
  683. bitmap_pair bitmap_pairs[] =
  684. {
  685. {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  686. {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  687. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  688. };
  689. if (display.epd2.panel == GxEPD2::GDEW029Z10)
  690. {
  691. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  692. {
  693. display.firstPage();
  694. do
  695. {
  696. display.fillScreen(GxEPD_WHITE);
  697. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  698. if (bitmap_pairs[i].red == WS_Bitmap3c128x296_red)
  699. {
  700. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  701. }
  702. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  703. }
  704. while (display.nextPage());
  705. delay(2000);
  706. }
  707. }
  708. }
  709. #endif
  710. #ifdef _GxBitmaps3c176x264_H_
  711. void drawBitmaps3c176x264()
  712. {
  713. bitmap_pair bitmap_pairs[] =
  714. {
  715. {Bitmap3c176x264_black, Bitmap3c176x264_red}
  716. };
  717. if (display.epd2.panel == GxEPD2::GDEW027C44)
  718. {
  719. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  720. {
  721. display.firstPage();
  722. do
  723. {
  724. display.fillScreen(GxEPD_WHITE);
  725. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  726. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  727. }
  728. while (display.nextPage());
  729. delay(2000);
  730. }
  731. }
  732. }
  733. #endif
  734. #ifdef _GxBitmaps3c400x300_H_
  735. void drawBitmaps3c400x300()
  736. {
  737. bitmap_pair bitmap_pairs[] =
  738. {
  739. {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
  740. {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
  741. {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
  742. };
  743. if (display.epd2.panel == GxEPD2::GDEW042Z15)
  744. {
  745. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  746. {
  747. display.firstPage();
  748. do
  749. {
  750. display.fillScreen(GxEPD_WHITE);
  751. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  752. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  753. }
  754. while (display.nextPage());
  755. delay(2000);
  756. }
  757. }
  758. }
  759. #endif