GxEPD2_MultiDisplayExample.ino 31 KB

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