GxEPD2_Example.ino 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  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: 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. // see GxEPD2_wiring_examples.h for wiring suggestions and examples
  15. // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  16. // enable or disable GxEPD2_GFX base class
  17. #define ENABLE_GxEPD2_GFX 0
  18. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  19. //#include <GFX.h>
  20. // Note: if you use this with ENABLE_GxEPD2_GFX 1:
  21. // uncomment it in GxEPD2_GFX.h too, or add #include <GFX.h> before any #include <GxEPD2_GFX.h>
  22. #include <GxEPD2_BW.h>
  23. #include <GxEPD2_3C.h>
  24. #include <GxEPD2_7C.h>
  25. #include <Fonts/FreeMonoBold9pt7b.h>
  26. // select the display constructor line in one of the following files (old style):
  27. #include "GxEPD2_display_selection.h"
  28. #include "GxEPD2_display_selection_added.h"
  29. //#include "GxEPD2_display_selection_more.h" // private
  30. // or select the display class and display driver class in the following file (new style):
  31. #include "GxEPD2_display_selection_new_style.h"
  32. #if !defined(__AVR) && !defined(_BOARD_GENERIC_STM32F103C_H_)
  33. // note 16.11.2019: the compiler may exclude code based on constant if statements (display.epd2.panel == constant),
  34. // therefore bitmaps may get optimized out by the linker
  35. // comment out unused bitmaps to reduce code space used
  36. #include "bitmaps/Bitmaps80x128.h" // 1.02" b/w
  37. #include "bitmaps/Bitmaps152x152.h" // 1.54" b/w
  38. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  39. #include "bitmaps/Bitmaps104x212.h" // 2.13" b/w flexible GDEW0213I5F
  40. #include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  41. #include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  42. #include "bitmaps/Bitmaps152x296.h" // 2.6" b/w
  43. #include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  44. #include "bitmaps/Bitmaps240x416.h" // 3.71" b/w
  45. #include "bitmaps/Bitmaps400x300.h" // 4.2" b/w
  46. #include "bitmaps/Bitmaps648x480.h" // 5.38" b/w
  47. #include "bitmaps/Bitmaps640x384.h" // 7.5" b/w
  48. #include "bitmaps/Bitmaps800x480.h" // 7.5" b/w
  49. // 3-color
  50. #include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  51. #include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  52. #include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  53. #include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  54. #include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r
  55. #if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
  56. #include "bitmaps/Bitmaps3c800x480.h" // 7.5" b/w/r
  57. #include "bitmaps/Bitmaps3c880x528.h" // 7.5" b/w/r
  58. #include "bitmaps/WS_Bitmaps800x600.h" // 6.0" grey
  59. #include "bitmaps/WS_Bitmaps7c192x143.h" // 5.65" 7-color
  60. #endif
  61. #if defined(ESP32)
  62. #include "bitmaps/Bitmaps1304x984.h" // 12.48" b/w
  63. #endif
  64. #else
  65. // select only one to fit in code space
  66. //#include "bitmaps/Bitmaps80x128.h" // 1.02" b/w
  67. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  68. //#include "bitmaps/Bitmaps104x212.h" // 2.13" b/w flexible GDEW0213I5F
  69. //#include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  70. //#include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  71. //#include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  72. ////#include "bitmaps/Bitmaps400x300.h" // 4.2" b/w // not enough code space
  73. ////#include "bitmaps/Bitmaps640x384.h" // 7.5" b/w // not enough code space
  74. // 3-color
  75. //#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  76. //#include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  77. //#include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  78. //#include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  79. ////#include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r // not enough code space
  80. #endif
  81. void setup()
  82. {
  83. Serial.begin(115200);
  84. Serial.println();
  85. Serial.println("setup");
  86. delay(100);
  87. display.init(115200);
  88. // first update should be full refresh
  89. helloWorld();
  90. delay(1000);
  91. // partial refresh mode can be used to full screen,
  92. // effective if display panel hasFastPartialUpdate
  93. helloFullScreenPartialMode();
  94. delay(1000);
  95. //stripeTest(); return; // GDEH029Z13 issue
  96. helloArduino();
  97. delay(1000);
  98. helloEpaper();
  99. delay(1000);
  100. //helloValue(123.9, 1);
  101. //delay(1000);
  102. showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
  103. delay(1000);
  104. if (display.epd2.WIDTH < 104)
  105. {
  106. showFont("glcdfont", 0);
  107. delay(1000);
  108. }
  109. drawBitmaps();
  110. #if !defined(__AVR) // takes too long!
  111. if (display.epd2.panel == GxEPD2::ACeP565)
  112. {
  113. //draw7colorlines();
  114. //delay(2000);
  115. draw7colors();
  116. delay(4000);
  117. }
  118. #endif
  119. if (display.epd2.hasPartialUpdate)
  120. {
  121. showPartialUpdate();
  122. delay(1000);
  123. } // else // on GDEW0154Z04 only full update available, doesn't look nice
  124. //drawCornerTest();
  125. //showBox(16, 16, 48, 32, false);
  126. //showBox(16, 56, 48, 32, true);
  127. display.powerOff();
  128. deepSleepTest();
  129. #if defined(ESP32) && defined(_GxBitmaps1304x984_H_)
  130. drawBitmaps1304x984();
  131. display.powerOff();
  132. #endif
  133. Serial.println("setup done");
  134. }
  135. void loop()
  136. {
  137. }
  138. // note for partial update window and setPartialWindow() method:
  139. // partial update window size and position is on byte boundary in physical x direction
  140. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  141. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  142. const char HelloWorld[] = "Hello World!";
  143. const char HelloArduino[] = "Hello Arduino!";
  144. const char HelloEpaper[] = "Hello E-Paper!";
  145. void helloWorld()
  146. {
  147. //Serial.println("helloWorld");
  148. display.setRotation(1);
  149. display.setFont(&FreeMonoBold9pt7b);
  150. if (display.epd2.WIDTH < 104) display.setFont(0);
  151. display.setTextColor(GxEPD_BLACK);
  152. int16_t tbx, tby; uint16_t tbw, tbh;
  153. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  154. // center bounding box by transposition of origin:
  155. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  156. uint16_t y = ((display.height() - tbh) / 2) - tby;
  157. display.setFullWindow();
  158. display.firstPage();
  159. do
  160. {
  161. display.fillScreen(GxEPD_WHITE);
  162. display.setCursor(x, y);
  163. display.print(HelloWorld);
  164. }
  165. while (display.nextPage());
  166. //Serial.println("helloWorld done");
  167. }
  168. void helloWorldForDummies()
  169. {
  170. //Serial.println("helloWorld");
  171. const char text[] = "Hello World!";
  172. // most e-papers have width < height (portrait) as native orientation, especially the small ones
  173. // in GxEPD2 rotation 0 is used for native orientation (most TFT libraries use 0 fix for portrait orientation)
  174. // set rotation to 1 (rotate right 90 degrees) to have enough space on small displays (landscape)
  175. display.setRotation(1);
  176. // select a suitable font in Adafruit_GFX
  177. display.setFont(&FreeMonoBold9pt7b);
  178. // on e-papers black on white is more pleasant to read
  179. display.setTextColor(GxEPD_BLACK);
  180. // Adafruit_GFX has a handy method getTextBounds() to determine the boundary box for a text for the actual font
  181. int16_t tbx, tby; uint16_t tbw, tbh; // boundary box window
  182. display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh); // it works for origin 0, 0, fortunately (negative tby!)
  183. // center bounding box by transposition of origin:
  184. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  185. uint16_t y = ((display.height() - tbh) / 2) - tby;
  186. // full window mode is the initial mode, set it anyway
  187. display.setFullWindow();
  188. // here we use paged drawing, even if the processor has enough RAM for full buffer
  189. // so this can be used with any supported processor board.
  190. // the cost in code overhead and execution time penalty is marginal
  191. // tell the graphics class to use paged drawing mode
  192. display.firstPage();
  193. do
  194. {
  195. // this part of code is executed multiple times, as many as needed,
  196. // in case of full buffer it is executed once
  197. // IMPORTANT: each iteration needs to draw the same, to avoid strange effects
  198. // use a copy of values that might change, don't read e.g. from analog or pins in the loop!
  199. display.fillScreen(GxEPD_WHITE); // set the background to white (fill the buffer with value for white)
  200. display.setCursor(x, y); // set the postition to start printing text
  201. display.print(text); // print some text
  202. // end of part executed multiple times
  203. }
  204. // tell the graphics class to transfer the buffer content (page) to the controller buffer
  205. // the graphics class will command the controller to refresh to the screen when the last page has been transferred
  206. // returns true if more pages need be drawn and transferred
  207. // returns false if the last page has been transferred and the screen refreshed for panels without fast partial update
  208. // returns false for panels with fast partial update when the controller buffer has been written once more, to make the differential buffers equal
  209. // (for full buffered with fast partial update the (full) buffer is just transferred again, and false returned)
  210. while (display.nextPage());
  211. //Serial.println("helloWorld done");
  212. }
  213. void helloFullScreenPartialMode()
  214. {
  215. //Serial.println("helloFullScreenPartialMode");
  216. const char fullscreen[] = "full screen update";
  217. const char fpm[] = "fast partial mode";
  218. const char spm[] = "slow partial mode";
  219. const char npm[] = "no partial mode";
  220. display.setPartialWindow(0, 0, display.width(), display.height());
  221. display.setRotation(1);
  222. display.setFont(&FreeMonoBold9pt7b);
  223. if (display.epd2.WIDTH < 104) display.setFont(0);
  224. display.setTextColor(GxEPD_BLACK);
  225. const char* updatemode;
  226. if (display.epd2.hasFastPartialUpdate)
  227. {
  228. updatemode = fpm;
  229. }
  230. else if (display.epd2.hasPartialUpdate)
  231. {
  232. updatemode = spm;
  233. }
  234. else
  235. {
  236. updatemode = npm;
  237. }
  238. // do this outside of the loop
  239. int16_t tbx, tby; uint16_t tbw, tbh;
  240. // center update text
  241. display.getTextBounds(fullscreen, 0, 0, &tbx, &tby, &tbw, &tbh);
  242. uint16_t utx = ((display.width() - tbw) / 2) - tbx;
  243. uint16_t uty = ((display.height() / 4) - tbh / 2) - tby;
  244. // center update mode
  245. display.getTextBounds(updatemode, 0, 0, &tbx, &tby, &tbw, &tbh);
  246. uint16_t umx = ((display.width() - tbw) / 2) - tbx;
  247. uint16_t umy = ((display.height() * 3 / 4) - tbh / 2) - tby;
  248. // center HelloWorld
  249. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  250. uint16_t hwx = ((display.width() - tbw) / 2) - tbx;
  251. uint16_t hwy = ((display.height() - tbh) / 2) - tby;
  252. display.firstPage();
  253. do
  254. {
  255. display.fillScreen(GxEPD_WHITE);
  256. display.setCursor(hwx, hwy);
  257. display.print(HelloWorld);
  258. display.setCursor(utx, uty);
  259. display.print(fullscreen);
  260. display.setCursor(umx, umy);
  261. display.print(updatemode);
  262. }
  263. while (display.nextPage());
  264. //Serial.println("helloFullScreenPartialMode done");
  265. }
  266. void helloArduino()
  267. {
  268. //Serial.println("helloArduino");
  269. display.setRotation(1);
  270. display.setFont(&FreeMonoBold9pt7b);
  271. if (display.epd2.WIDTH < 104) display.setFont(0);
  272. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  273. int16_t tbx, tby; uint16_t tbw, tbh;
  274. // align with centered HelloWorld
  275. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  276. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  277. // height might be different
  278. display.getTextBounds(HelloArduino, 0, 0, &tbx, &tby, &tbw, &tbh);
  279. uint16_t y = ((display.height() / 4) - tbh / 2) - tby; // y is base line!
  280. // make the window big enough to cover (overwrite) descenders of previous text
  281. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  282. uint16_t wy = (display.height() / 4) - wh / 2;
  283. display.setPartialWindow(0, wy, display.width(), wh);
  284. display.firstPage();
  285. do
  286. {
  287. display.fillScreen(GxEPD_WHITE);
  288. //display.drawRect(x, y - tbh, tbw, tbh, GxEPD_BLACK);
  289. display.setCursor(x, y);
  290. display.print(HelloArduino);
  291. }
  292. while (display.nextPage());
  293. delay(1000);
  294. //Serial.println("helloArduino done");
  295. }
  296. void helloEpaper()
  297. {
  298. //Serial.println("helloEpaper");
  299. display.setRotation(1);
  300. display.setFont(&FreeMonoBold9pt7b);
  301. if (display.epd2.WIDTH < 104) display.setFont(0);
  302. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  303. int16_t tbx, tby; uint16_t tbw, tbh;
  304. // align with centered HelloWorld
  305. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  306. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  307. // height might be different
  308. display.getTextBounds(HelloEpaper, 0, 0, &tbx, &tby, &tbw, &tbh);
  309. uint16_t y = ((display.height() * 3 / 4) - tbh / 2) - tby; // y is base line!
  310. // make the window big enough to cover (overwrite) descenders of previous text
  311. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  312. uint16_t wy = (display.height() * 3 / 4) - wh / 2;
  313. display.setPartialWindow(0, wy, display.width(), wh);
  314. display.firstPage();
  315. do
  316. {
  317. display.fillScreen(GxEPD_WHITE);
  318. display.setCursor(x, y);
  319. display.print(HelloEpaper);
  320. }
  321. while (display.nextPage());
  322. //Serial.println("helloEpaper done");
  323. }
  324. // test partial window issue on GDEW0213Z19 and GDEH029Z13
  325. void stripeTest()
  326. {
  327. helloStripe(104);
  328. delay(2000);
  329. helloStripe(96);
  330. }
  331. const char HelloStripe[] = "Hello Stripe!";
  332. void helloStripe(uint16_t pw_xe) // end of partial window in physcal x direction
  333. {
  334. //Serial.print("HelloStripe("); Serial.print(pw_xe); Serial.println(")");
  335. display.setRotation(3);
  336. display.setFont(&FreeMonoBold9pt7b);
  337. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  338. int16_t tbx, tby; uint16_t tbw, tbh;
  339. display.getTextBounds(HelloStripe, 0, 0, &tbx, &tby, &tbw, &tbh);
  340. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  341. uint16_t wy = pw_xe - wh;
  342. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  343. uint16_t y = wy - tby;
  344. display.setPartialWindow(0, wy, display.width(), wh);
  345. display.firstPage();
  346. do
  347. {
  348. display.fillScreen(GxEPD_WHITE);
  349. display.setCursor(x, y);
  350. display.print(HelloStripe);
  351. }
  352. while (display.nextPage());
  353. //Serial.println("HelloStripe done");
  354. }
  355. #if defined(ESP8266) || defined(ESP32)
  356. #include <StreamString.h>
  357. #define PrintString StreamString
  358. #else
  359. class PrintString : public Print, public String
  360. {
  361. public:
  362. size_t write(uint8_t data) override
  363. {
  364. return concat(char(data));
  365. };
  366. };
  367. #endif
  368. void helloValue(double v, int digits)
  369. {
  370. //Serial.println("helloValue");
  371. display.setRotation(1);
  372. display.setFont(&FreeMonoBold9pt7b);
  373. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  374. PrintString valueString;
  375. valueString.print(v, digits);
  376. int16_t tbx, tby; uint16_t tbw, tbh;
  377. display.getTextBounds(valueString, 0, 0, &tbx, &tby, &tbw, &tbh);
  378. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  379. uint16_t y = ((display.height() * 3 / 4) - tbh / 2) - tby; // y is base line!
  380. // show what happens, if we use the bounding box for partial window
  381. uint16_t wx = (display.width() - tbw) / 2;
  382. uint16_t wy = ((display.height() * 3 / 4) - tbh / 2) - tby; // y is base line!
  383. display.setPartialWindow(wx, wy, tbw, tbh);
  384. display.firstPage();
  385. do
  386. {
  387. display.fillScreen(GxEPD_WHITE);
  388. display.setCursor(x, y);
  389. display.print(valueString);
  390. }
  391. while (display.nextPage());
  392. delay(2000);
  393. // make the partial window big enough to cover the previous text
  394. uint16_t ww = tbw; // remember window width
  395. display.getTextBounds(HelloEpaper, 0, 0, &tbx, &tby, &tbw, &tbh);
  396. // adjust, because HelloEpaper was aligned, not centered (could calculate this to be precise)
  397. ww = max(ww, uint16_t(tbw + 12)); // 12 seems ok
  398. wx = (display.width() - tbw) / 2;
  399. // make the window big enough to cover (overwrite) descenders of previous text
  400. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  401. wy = (display.height() * 3 / 4) - wh / 2;
  402. display.setPartialWindow(wx, wy, ww, wh);
  403. // alternately use the whole width for partial window
  404. //display.setPartialWindow(0, wy, display.width(), wh);
  405. display.firstPage();
  406. do
  407. {
  408. display.fillScreen(GxEPD_WHITE);
  409. display.setCursor(x, y);
  410. display.print(valueString);
  411. }
  412. while (display.nextPage());
  413. //Serial.println("helloValue done");
  414. }
  415. void deepSleepTest()
  416. {
  417. //Serial.println("deepSleepTest");
  418. const char hibernating[] = "hibernating ...";
  419. const char wokeup[] = "woke up";
  420. const char from[] = "from deep sleep";
  421. const char again[] = "again";
  422. display.setRotation(1);
  423. display.setFont(&FreeMonoBold9pt7b);
  424. if (display.epd2.WIDTH < 104) display.setFont(0);
  425. display.setTextColor(GxEPD_BLACK);
  426. int16_t tbx, tby; uint16_t tbw, tbh;
  427. // center text
  428. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  429. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  430. uint16_t y = ((display.height() - tbh) / 2) - tby;
  431. display.setFullWindow();
  432. display.firstPage();
  433. do
  434. {
  435. display.fillScreen(GxEPD_WHITE);
  436. display.setCursor(x, y);
  437. display.print(hibernating);
  438. }
  439. while (display.nextPage());
  440. display.hibernate();
  441. delay(5000);
  442. display.getTextBounds(wokeup, 0, 0, &tbx, &tby, &tbw, &tbh);
  443. uint16_t wx = (display.width() - tbw) / 2;
  444. uint16_t wy = ((display.height() / 3) - tbh / 2) - tby; // y is base line!
  445. display.getTextBounds(from, 0, 0, &tbx, &tby, &tbw, &tbh);
  446. uint16_t fx = (display.width() - tbw) / 2;
  447. uint16_t fy = ((display.height() * 2 / 3) - tbh / 2) - tby; // y is base line!
  448. display.firstPage();
  449. do
  450. {
  451. display.fillScreen(GxEPD_WHITE);
  452. display.setCursor(wx, wy);
  453. display.print(wokeup);
  454. display.setCursor(fx, fy);
  455. display.print(from);
  456. }
  457. while (display.nextPage());
  458. delay(5000);
  459. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  460. uint16_t hx = (display.width() - tbw) / 2;
  461. uint16_t hy = ((display.height() / 3) - tbh / 2) - tby; // y is base line!
  462. display.getTextBounds(again, 0, 0, &tbx, &tby, &tbw, &tbh);
  463. uint16_t ax = (display.width() - tbw) / 2;
  464. uint16_t ay = ((display.height() * 2 / 3) - tbh / 2) - tby; // y is base line!
  465. display.firstPage();
  466. do
  467. {
  468. display.fillScreen(GxEPD_WHITE);
  469. display.setCursor(hx, hy);
  470. display.print(hibernating);
  471. display.setCursor(ax, ay);
  472. display.print(again);
  473. }
  474. while (display.nextPage());
  475. display.hibernate();
  476. //Serial.println("deepSleepTest done");
  477. }
  478. void showBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool partial)
  479. {
  480. //Serial.println("showBox");
  481. display.setRotation(1);
  482. if (partial)
  483. {
  484. display.setPartialWindow(x, y, w, h);
  485. }
  486. else
  487. {
  488. display.setFullWindow();
  489. }
  490. display.firstPage();
  491. do
  492. {
  493. display.fillScreen(GxEPD_WHITE);
  494. display.fillRect(x, y, w, h, GxEPD_BLACK);
  495. }
  496. while (display.nextPage());
  497. //Serial.println("showBox done");
  498. }
  499. void drawCornerTest()
  500. {
  501. display.setFullWindow();
  502. display.setFont(&FreeMonoBold9pt7b);
  503. display.setTextColor(GxEPD_BLACK);
  504. for (uint16_t r = 0; r <= 4; r++)
  505. {
  506. display.setRotation(r);
  507. display.firstPage();
  508. do
  509. {
  510. display.fillScreen(GxEPD_WHITE);
  511. display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
  512. display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
  513. display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
  514. display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
  515. display.setCursor(display.width() / 2, display.height() / 2);
  516. display.print(display.getRotation());
  517. }
  518. while (display.nextPage());
  519. delay(2000);
  520. }
  521. }
  522. void showFont(const char name[], const GFXfont* f)
  523. {
  524. display.setFullWindow();
  525. display.setRotation(0);
  526. display.setTextColor(GxEPD_BLACK);
  527. display.firstPage();
  528. do
  529. {
  530. drawFont(name, f);
  531. }
  532. while (display.nextPage());
  533. }
  534. void drawFont(const char name[], const GFXfont* f)
  535. {
  536. //display.setRotation(0);
  537. display.fillScreen(GxEPD_WHITE);
  538. display.setTextColor(GxEPD_BLACK);
  539. display.setFont(f);
  540. display.setCursor(0, 0);
  541. display.println();
  542. display.println(name);
  543. display.println(" !\"#$%&'()*+,-./");
  544. display.println("0123456789:;<=>?");
  545. display.println("@ABCDEFGHIJKLMNO");
  546. display.println("PQRSTUVWXYZ[\\]^_");
  547. if (display.epd2.hasColor)
  548. {
  549. display.setTextColor(GxEPD_RED);
  550. }
  551. display.println("`abcdefghijklmno");
  552. display.println("pqrstuvwxyz{|}~ ");
  553. }
  554. // note for partial update window and setPartialWindow() method:
  555. // partial update window size and position is on byte boundary in physical x direction
  556. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  557. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  558. // showPartialUpdate() purposely uses values that are not multiples of 8 to test this
  559. void showPartialUpdate()
  560. {
  561. // some useful background
  562. helloWorld();
  563. // use asymmetric values for test
  564. uint16_t box_x = 10;
  565. uint16_t box_y = 15;
  566. uint16_t box_w = 70;
  567. uint16_t box_h = 20;
  568. uint16_t cursor_y = box_y + box_h - 6;
  569. if (display.epd2.WIDTH < 104) cursor_y = box_y + 6;
  570. float value = 13.95;
  571. uint16_t incr = display.epd2.hasFastPartialUpdate ? 1 : 3;
  572. display.setFont(&FreeMonoBold9pt7b);
  573. if (display.epd2.WIDTH < 104) display.setFont(0);
  574. display.setTextColor(GxEPD_BLACK);
  575. // show where the update box is
  576. for (uint16_t r = 0; r < 4; r++)
  577. {
  578. display.setRotation(r);
  579. display.setPartialWindow(box_x, box_y, box_w, box_h);
  580. display.firstPage();
  581. do
  582. {
  583. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_BLACK);
  584. //display.fillScreen(GxEPD_BLACK);
  585. }
  586. while (display.nextPage());
  587. delay(2000);
  588. display.firstPage();
  589. do
  590. {
  591. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  592. }
  593. while (display.nextPage());
  594. delay(1000);
  595. }
  596. //return;
  597. // show updates in the update box
  598. for (uint16_t r = 0; r < 4; r++)
  599. {
  600. display.setRotation(r);
  601. display.setPartialWindow(box_x, box_y, box_w, box_h);
  602. for (uint16_t i = 1; i <= 10; i += incr)
  603. {
  604. display.firstPage();
  605. do
  606. {
  607. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  608. display.setCursor(box_x, cursor_y);
  609. display.print(value * i, 2);
  610. }
  611. while (display.nextPage());
  612. delay(500);
  613. }
  614. delay(1000);
  615. display.firstPage();
  616. do
  617. {
  618. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  619. }
  620. while (display.nextPage());
  621. delay(1000);
  622. }
  623. }
  624. void drawBitmaps()
  625. {
  626. display.setFullWindow();
  627. #ifdef _GxBitmaps80x128_H_
  628. drawBitmaps80x128();
  629. #endif
  630. #ifdef _GxBitmaps152x152_H_
  631. drawBitmaps152x152();
  632. #endif
  633. #ifdef _GxBitmaps104x212_H_
  634. drawBitmaps104x212();
  635. #endif
  636. #ifdef _GxBitmaps128x250_H_
  637. drawBitmaps128x250();
  638. #endif
  639. #ifdef _GxBitmaps128x296_H_
  640. drawBitmaps128x296();
  641. #endif
  642. #ifdef _GxBitmaps176x264_H_
  643. drawBitmaps176x264();
  644. #endif
  645. #ifdef _GxBitmaps400x300_H_
  646. drawBitmaps400x300();
  647. #endif
  648. #ifdef _GxBitmaps640x384_H_
  649. drawBitmaps640x384();
  650. #endif
  651. #ifdef _GxBitmaps648x480_H_
  652. drawBitmaps648x480();
  653. #endif
  654. #ifdef _GxBitmaps800x480_H_
  655. drawBitmaps800x480();
  656. #endif
  657. #ifdef _WS_Bitmaps800x600_H_
  658. drawBitmaps800x600();
  659. #endif
  660. #if defined(ESP32) && defined(_GxBitmaps1304x984_H_)
  661. drawBitmaps1304x984();
  662. #endif
  663. // 3-color
  664. #ifdef _GxBitmaps3c104x212_H_
  665. drawBitmaps3c104x212();
  666. #endif
  667. #ifdef _GxBitmaps3c128x296_H_
  668. drawBitmaps3c128x296();
  669. #endif
  670. #ifdef _GxBitmaps152x296_H_
  671. drawBitmaps152x296();
  672. #endif
  673. #ifdef _GxBitmaps3c176x264_H_
  674. drawBitmaps3c176x264();
  675. #endif
  676. #ifdef _GxBitmaps240x416_H_
  677. drawBitmaps240x416();
  678. #endif
  679. #ifdef _GxBitmaps3c400x300_H_
  680. drawBitmaps3c400x300();
  681. #endif
  682. #ifdef _GxBitmaps3c800x480_H_
  683. drawBitmaps3c800x480();
  684. #endif
  685. #ifdef _GxBitmaps3c880x528_H_
  686. drawBitmaps3c880x528();
  687. #endif
  688. #if defined(_WS_Bitmaps7c192x143_H_)
  689. drawBitmaps7c192x143();
  690. #endif
  691. if ((display.epd2.WIDTH >= 200) && (display.epd2.HEIGHT >= 200))
  692. {
  693. // show these after the specific bitmaps
  694. #ifdef _GxBitmaps200x200_H_
  695. drawBitmaps200x200();
  696. #endif
  697. // 3-color
  698. #ifdef _GxBitmaps3c200x200_H_
  699. drawBitmaps3c200x200();
  700. #endif
  701. }
  702. }
  703. #ifdef _GxBitmaps80x128_H_
  704. void drawBitmaps80x128()
  705. {
  706. #if !defined(__AVR)
  707. const unsigned char* bitmaps[] =
  708. {
  709. Bitmap80x128_1, Bitmap80x128_2, Bitmap80x128_3, Bitmap80x128_4, Bitmap80x128_5
  710. };
  711. #else
  712. const unsigned char* bitmaps[] =
  713. {
  714. Bitmap80x128_1, Bitmap80x128_2, Bitmap80x128_3, Bitmap80x128_4, Bitmap80x128_5
  715. };
  716. #endif
  717. if ((display.epd2.WIDTH == 80) && (display.epd2.HEIGHT == 128))
  718. {
  719. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  720. {
  721. display.firstPage();
  722. do
  723. {
  724. display.fillScreen(GxEPD_WHITE);
  725. display.drawInvertedBitmap(0, 0, bitmaps[i], 80, 128, GxEPD_BLACK);
  726. }
  727. while (display.nextPage());
  728. delay(2000);
  729. }
  730. display.firstPage();
  731. do
  732. {
  733. display.fillScreen(GxEPD_WHITE);
  734. display.drawBitmap(0, 0, WS_Bitmap80x128, 80, 128, GxEPD_BLACK);
  735. }
  736. while (display.nextPage());
  737. delay(2000);
  738. }
  739. }
  740. #endif
  741. #ifdef _GxBitmaps152x152_H_
  742. void drawBitmaps152x152()
  743. {
  744. #if !defined(__AVR)
  745. const unsigned char* bitmaps[] =
  746. {
  747. Bitmap152x152_1, Bitmap152x152_2, Bitmap152x152_3
  748. };
  749. #else
  750. const unsigned char* bitmaps[] =
  751. {
  752. Bitmap152x152_1, Bitmap152x152_2, Bitmap152x152_3
  753. };
  754. #endif
  755. if ((display.epd2.WIDTH == 152) && (display.epd2.HEIGHT == 152))
  756. {
  757. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  758. {
  759. display.firstPage();
  760. do
  761. {
  762. display.fillScreen(GxEPD_WHITE);
  763. display.drawInvertedBitmap(0, 0, bitmaps[i], 152, 152, GxEPD_BLACK);
  764. }
  765. while (display.nextPage());
  766. delay(2000);
  767. }
  768. }
  769. }
  770. #endif
  771. #ifdef _GxBitmaps200x200_H_
  772. void drawBitmaps200x200()
  773. {
  774. #if defined(ARDUINO_AVR_PRO)
  775. const unsigned char* bitmaps[] =
  776. {
  777. logo200x200
  778. };
  779. #elif defined(__AVR)
  780. const unsigned char* bitmaps[] =
  781. {
  782. logo200x200, //first200x200
  783. };
  784. #elif defined(_BOARD_GENERIC_STM32F103C_H_) || defined(STM32F1xx)
  785. const unsigned char* bitmaps[] =
  786. {
  787. logo200x200, first200x200, second200x200, third200x200, //fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  788. };
  789. #else
  790. const unsigned char* bitmaps[] =
  791. {
  792. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  793. };
  794. #endif
  795. if ((display.epd2.WIDTH == 200) && (display.epd2.HEIGHT == 200) && !display.epd2.hasColor)
  796. {
  797. bool m = display.mirror(true);
  798. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  799. {
  800. display.firstPage();
  801. do
  802. {
  803. display.fillScreen(GxEPD_WHITE);
  804. display.drawInvertedBitmap(0, 0, bitmaps[i], 200, 200, GxEPD_BLACK);
  805. }
  806. while (display.nextPage());
  807. delay(2000);
  808. }
  809. display.mirror(m);
  810. }
  811. //else
  812. {
  813. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  814. display.clearScreen(); // use default for white
  815. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  816. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  817. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  818. {
  819. display.drawImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  820. delay(2000);
  821. }
  822. }
  823. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  824. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  825. {
  826. int16_t x = -60;
  827. int16_t y = -60;
  828. for (uint16_t j = 0; j < 10; j++)
  829. {
  830. display.writeScreenBuffer(); // use default for white
  831. display.writeImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  832. display.refresh(true);
  833. if (display.epd2.hasFastPartialUpdate)
  834. {
  835. // for differential update: set previous buffer equal to current buffer in controller
  836. display.epd2.writeScreenBufferAgain(); // use default for white
  837. display.epd2.writeImageAgain(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  838. }
  839. delay(2000);
  840. x += display.epd2.WIDTH / 4;
  841. y += display.epd2.HEIGHT / 4;
  842. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  843. }
  844. if (!display.epd2.hasFastPartialUpdate) break; // comment out for full show
  845. break; // comment out for full show
  846. }
  847. display.writeScreenBuffer(); // use default for white
  848. display.writeImage(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  849. display.writeImage(bitmaps[0], int16_t(int16_t(display.epd2.WIDTH) - 200), int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, mirror_y, true);
  850. display.refresh(true);
  851. // for differential update: set previous buffer equal to current buffer in controller
  852. display.epd2.writeScreenBufferAgain(); // use default for white
  853. display.epd2.writeImageAgain(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  854. display.epd2.writeImageAgain(bitmaps[0], int16_t(int16_t(display.epd2.WIDTH) - 200), int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, mirror_y, true);
  855. delay(2000);
  856. }
  857. #endif
  858. #ifdef _GxBitmaps104x212_H_
  859. void drawBitmaps104x212()
  860. {
  861. #if !defined(__AVR)
  862. const unsigned char* bitmaps[] =
  863. {
  864. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  865. };
  866. #else
  867. const unsigned char* bitmaps[] =
  868. {
  869. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  870. };
  871. #endif
  872. if ((display.epd2.WIDTH == 104) && (display.epd2.HEIGHT == 212) && !display.epd2.hasColor)
  873. {
  874. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  875. {
  876. display.firstPage();
  877. do
  878. {
  879. display.fillScreen(GxEPD_WHITE);
  880. display.drawBitmap(0, 0, bitmaps[i], 104, 212, GxEPD_BLACK);
  881. }
  882. while (display.nextPage());
  883. delay(2000);
  884. }
  885. }
  886. }
  887. #endif
  888. #ifdef _GxBitmaps128x250_H_
  889. void drawBitmaps128x250()
  890. {
  891. #if !defined(__AVR)
  892. const unsigned char* bitmaps[] =
  893. {
  894. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  895. };
  896. #else
  897. const unsigned char* bitmaps[] =
  898. {
  899. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  900. };
  901. #endif
  902. if ((display.epd2.WIDTH == 128) && (display.epd2.HEIGHT == 250) && !display.epd2.hasColor)
  903. {
  904. bool m = display.mirror(true);
  905. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  906. {
  907. display.firstPage();
  908. do
  909. {
  910. display.fillScreen(GxEPD_WHITE);
  911. display.drawInvertedBitmap(0, 0, bitmaps[i], 128, 250, GxEPD_BLACK);
  912. }
  913. while (display.nextPage());
  914. delay(2000);
  915. }
  916. display.mirror(m);
  917. }
  918. }
  919. #endif
  920. #ifdef _GxBitmaps128x296_H_
  921. void drawBitmaps128x296()
  922. {
  923. #if !defined(__AVR)
  924. const unsigned char* bitmaps[] =
  925. {
  926. Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
  927. };
  928. #else
  929. const unsigned char* bitmaps[] =
  930. {
  931. Bitmap128x296_1, logo128x296 //, first128x296, second128x296, third128x296
  932. };
  933. #endif
  934. if ((display.epd2.WIDTH == 128) && (display.epd2.HEIGHT == 296) && !display.epd2.hasColor)
  935. {
  936. bool m = display.mirror(true);
  937. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  938. {
  939. display.firstPage();
  940. do
  941. {
  942. display.fillScreen(GxEPD_WHITE);
  943. display.drawInvertedBitmap(0, 0, bitmaps[i], 128, 296, GxEPD_BLACK);
  944. }
  945. while (display.nextPage());
  946. delay(2000);
  947. }
  948. display.mirror(m);
  949. }
  950. }
  951. #endif
  952. #ifdef _GxBitmaps152x296_H_
  953. void drawBitmaps152x296()
  954. {
  955. #if !defined(__AVR)
  956. const unsigned char* bitmaps[] =
  957. {
  958. Bitmap152x296_1, Bitmap152x296_2, Bitmap152x296_3
  959. };
  960. #else
  961. const unsigned char* bitmaps[] =
  962. {
  963. Bitmap152x296_1, Bitmap152x296_2, Bitmap152x296_3
  964. };
  965. #endif
  966. if ((display.epd2.WIDTH == 152) && (display.epd2.HEIGHT == 296) && !display.epd2.hasColor)
  967. {
  968. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  969. {
  970. display.firstPage();
  971. do
  972. {
  973. display.fillScreen(GxEPD_WHITE);
  974. display.drawInvertedBitmap(0, 0, bitmaps[i], 152, 296, GxEPD_BLACK);
  975. }
  976. while (display.nextPage());
  977. delay(2000);
  978. }
  979. }
  980. }
  981. #endif
  982. #ifdef _GxBitmaps176x264_H_
  983. void drawBitmaps176x264()
  984. {
  985. #if !defined(__AVR)
  986. const unsigned char* bitmaps[] =
  987. {
  988. Bitmap176x264_1, Bitmap176x264_2, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  989. };
  990. #else
  991. const unsigned char* bitmaps[] =
  992. {
  993. Bitmap176x264_1, Bitmap176x264_2 //, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  994. };
  995. #endif
  996. if ((display.epd2.WIDTH == 176) && (display.epd2.HEIGHT == 264) && !display.epd2.hasColor)
  997. {
  998. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  999. {
  1000. display.firstPage();
  1001. do
  1002. {
  1003. display.fillScreen(GxEPD_WHITE);
  1004. display.drawInvertedBitmap(0, 0, bitmaps[i], 176, 264, GxEPD_BLACK);
  1005. }
  1006. while (display.nextPage());
  1007. delay(2000);
  1008. }
  1009. }
  1010. }
  1011. #endif
  1012. #ifdef _GxBitmaps240x416_H_
  1013. void drawBitmaps240x416()
  1014. {
  1015. #if !defined(__AVR)
  1016. const unsigned char* bitmaps[] =
  1017. {
  1018. Bitmap240x416_1, Bitmap240x416_2, Bitmap240x416_3
  1019. };
  1020. #else
  1021. const unsigned char* bitmaps[] =
  1022. {
  1023. Bitmap240x460_1, Bitmap240x460_2, Bitmap240x460_3
  1024. };
  1025. #endif
  1026. if ((display.epd2.WIDTH == 240) && (display.epd2.HEIGHT == 416) && !display.epd2.hasColor)
  1027. {
  1028. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1029. {
  1030. display.firstPage();
  1031. do
  1032. {
  1033. display.fillScreen(GxEPD_WHITE);
  1034. display.drawInvertedBitmap(0, 0, bitmaps[i], 240, 416, GxEPD_BLACK);
  1035. }
  1036. while (display.nextPage());
  1037. delay(2000);
  1038. }
  1039. }
  1040. }
  1041. #endif
  1042. #ifdef _GxBitmaps400x300_H_
  1043. void drawBitmaps400x300()
  1044. {
  1045. #if !defined(__AVR)
  1046. const unsigned char* bitmaps[] =
  1047. {
  1048. Bitmap400x300_1, Bitmap400x300_2
  1049. };
  1050. #else
  1051. const unsigned char* bitmaps[] = {}; // not enough code space
  1052. #endif
  1053. if ((display.epd2.WIDTH == 400) && (display.epd2.HEIGHT == 300) && !display.epd2.hasColor)
  1054. {
  1055. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1056. {
  1057. display.firstPage();
  1058. do
  1059. {
  1060. display.fillScreen(GxEPD_WHITE);
  1061. display.drawInvertedBitmap(0, 0, bitmaps[i], 400, 300, GxEPD_BLACK);
  1062. }
  1063. while (display.nextPage());
  1064. delay(2000);
  1065. }
  1066. }
  1067. }
  1068. #endif
  1069. #ifdef _GxBitmaps640x384_H_
  1070. void drawBitmaps640x384()
  1071. {
  1072. #if !defined(__AVR)
  1073. const unsigned char* bitmaps[] =
  1074. {
  1075. Bitmap640x384_1, Bitmap640x384_2
  1076. };
  1077. #else
  1078. const unsigned char* bitmaps[] = {}; // not enough code space
  1079. #endif
  1080. if ((display.epd2.WIDTH == 640) && (display.epd2.HEIGHT == 384))
  1081. {
  1082. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1083. {
  1084. display.firstPage();
  1085. do
  1086. {
  1087. display.fillScreen(GxEPD_WHITE);
  1088. display.drawInvertedBitmap(0, 0, bitmaps[i], 640, 384, GxEPD_BLACK);
  1089. }
  1090. while (display.nextPage());
  1091. delay(2000);
  1092. }
  1093. }
  1094. }
  1095. #endif
  1096. #ifdef _GxBitmaps648x480_H_
  1097. void drawBitmaps648x480()
  1098. {
  1099. #if !defined(__AVR)
  1100. const unsigned char* bitmaps[] =
  1101. {
  1102. Bitmap648x480_1, Bitmap648x480_2, Bitmap648x480_3
  1103. };
  1104. #else
  1105. const unsigned char* bitmaps[] = {}; // not enough code space
  1106. #endif
  1107. if ((display.epd2.WIDTH == 648) && (display.epd2.HEIGHT == 480) && !display.epd2.hasColor)
  1108. {
  1109. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1110. {
  1111. display.firstPage();
  1112. do
  1113. {
  1114. display.fillScreen(GxEPD_WHITE);
  1115. display.drawBitmap(0, 0, bitmaps[i], 648, 480, GxEPD_BLACK);
  1116. }
  1117. while (display.nextPage());
  1118. delay(2000);
  1119. }
  1120. }
  1121. }
  1122. #endif
  1123. #ifdef _GxBitmaps800x480_H_
  1124. void drawBitmaps800x480()
  1125. {
  1126. #if !defined(__AVR)
  1127. const unsigned char* bitmaps[] =
  1128. {
  1129. Bitmap800x480_1, Bitmap800x480_2, Bitmap800x480_3, Bitmap800x480_4
  1130. };
  1131. #else
  1132. const unsigned char* bitmaps[] = {}; // not enough code space
  1133. #endif
  1134. if ((display.epd2.WIDTH == 800) && (display.epd2.HEIGHT == 480))
  1135. {
  1136. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1137. {
  1138. display.firstPage();
  1139. do
  1140. {
  1141. display.fillScreen(GxEPD_WHITE);
  1142. display.drawBitmap(0, 0, bitmaps[i], 800, 480, GxEPD_BLACK);
  1143. }
  1144. while (display.nextPage());
  1145. delay(2000);
  1146. }
  1147. if (display.epd2.panel == GxEPD2::GDEW075T7)
  1148. {
  1149. // avoid ghosting caused by OTP waveform
  1150. display.clearScreen();
  1151. display.refresh(false); // full update
  1152. }
  1153. }
  1154. }
  1155. #endif
  1156. #ifdef _WS_Bitmaps800x600_H_
  1157. void drawBitmaps800x600()
  1158. {
  1159. #if defined(ESP8266) || defined(ESP32)
  1160. if ((display.epd2.panel == GxEPD2::ED060SCT) || (display.epd2.panel == GxEPD2::ED060KC1) || (display.epd2.panel == GxEPD2::ED078KC2))
  1161. {
  1162. // Serial.print("sizeof(WS_zoo_800x600) is "); Serial.println(sizeof(WS_zoo_800x600));
  1163. display.drawNative(WS_zoo_800x600, 0, 0, 0, 800, 600, false, false, true);
  1164. delay(2000);
  1165. // Serial.print("sizeof(WS_pic_1200x825) is "); Serial.println(sizeof(WS_pic_1200x825));
  1166. // display.drawNative((const uint8_t*)WS_pic_1200x825, 0, 0, 0, 1200, 825, false, false, true);
  1167. // delay(2000);
  1168. // Serial.print("sizeof(WS_acaa_1024x731) is "); Serial.println(sizeof(WS_acaa_1024x731));
  1169. // display.drawNative(WS_acaa_1024x731, 0, 0, 0, 1024, 731, false, false, true);
  1170. // delay(2000);
  1171. }
  1172. #endif
  1173. }
  1174. #endif
  1175. #if defined(ESP32) && defined(_GxBitmaps1304x984_H_)
  1176. void drawBitmaps1304x984()
  1177. {
  1178. if (display.epd2.panel == GxEPD2::GDEW1248T3)
  1179. {
  1180. display.drawImage(Bitmap1304x984, 0, 0, display.epd2.WIDTH, display.epd2.HEIGHT, false, false, true);
  1181. }
  1182. }
  1183. #endif
  1184. struct bitmap_pair
  1185. {
  1186. const unsigned char* black;
  1187. const unsigned char* red;
  1188. };
  1189. #ifdef _GxBitmaps3c200x200_H_
  1190. void drawBitmaps3c200x200()
  1191. {
  1192. bitmap_pair bitmap_pairs[] =
  1193. {
  1194. //{Bitmap3c200x200_black, Bitmap3c200x200_red},
  1195. {WS_Bitmap3c200x200_black, WS_Bitmap3c200x200_red}
  1196. };
  1197. if (display.epd2.panel == GxEPD2::GDEW0154Z04)
  1198. {
  1199. display.firstPage();
  1200. do
  1201. {
  1202. display.fillScreen(GxEPD_WHITE);
  1203. // Bitmap3c200x200_black has 2 bits per pixel
  1204. // taken from Adafruit_GFX.cpp, modified
  1205. int16_t byteWidth = (display.epd2.WIDTH + 7) / 8; // Bitmap scanline pad = whole byte
  1206. uint8_t byte = 0;
  1207. for (int16_t j = 0; j < display.epd2.HEIGHT; j++)
  1208. {
  1209. for (int16_t i = 0; i < display.epd2.WIDTH; i++)
  1210. {
  1211. if (i & 3) byte <<= 2;
  1212. else
  1213. {
  1214. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  1215. byte = pgm_read_byte(&Bitmap3c200x200_black[j * byteWidth * 2 + i / 4]);
  1216. #else
  1217. byte = Bitmap3c200x200_black[j * byteWidth * 2 + i / 4];
  1218. #endif
  1219. }
  1220. if (!(byte & 0x80))
  1221. {
  1222. display.drawPixel(i, j, GxEPD_BLACK);
  1223. }
  1224. }
  1225. }
  1226. display.drawInvertedBitmap(0, 0, Bitmap3c200x200_red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1227. }
  1228. while (display.nextPage());
  1229. delay(2000);
  1230. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1231. {
  1232. display.firstPage();
  1233. do
  1234. {
  1235. display.fillScreen(GxEPD_WHITE);
  1236. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1237. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1238. }
  1239. while (display.nextPage());
  1240. delay(2000);
  1241. }
  1242. }
  1243. if (display.epd2.hasColor)
  1244. {
  1245. display.clearScreen(); // use default for white
  1246. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  1247. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  1248. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1249. {
  1250. display.drawImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  1251. delay(2000);
  1252. }
  1253. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1254. {
  1255. int16_t x = -60;
  1256. int16_t y = -60;
  1257. for (uint16_t j = 0; j < 10; j++)
  1258. {
  1259. display.writeScreenBuffer(); // use default for white
  1260. display.writeImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  1261. display.refresh();
  1262. delay(1000);
  1263. x += display.epd2.WIDTH / 4;
  1264. y += display.epd2.HEIGHT / 4;
  1265. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  1266. }
  1267. }
  1268. display.writeScreenBuffer(); // use default for white
  1269. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, 0, 0, 200, 200, false, false, true);
  1270. 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);
  1271. display.refresh();
  1272. delay(2000);
  1273. }
  1274. }
  1275. #endif
  1276. #ifdef _GxBitmaps3c104x212_H_
  1277. void drawBitmaps3c104x212()
  1278. {
  1279. #if !defined(__AVR)
  1280. bitmap_pair bitmap_pairs[] =
  1281. {
  1282. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  1283. {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  1284. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  1285. };
  1286. #else
  1287. bitmap_pair bitmap_pairs[] =
  1288. {
  1289. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  1290. //{Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  1291. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  1292. };
  1293. #endif
  1294. if (display.epd2.panel == GxEPD2::GDEW0213Z16)
  1295. {
  1296. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1297. {
  1298. display.firstPage();
  1299. do
  1300. {
  1301. display.fillScreen(GxEPD_WHITE);
  1302. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1303. if (bitmap_pairs[i].red == WS_Bitmap3c104x212_red)
  1304. {
  1305. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1306. }
  1307. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1308. }
  1309. while (display.nextPage());
  1310. delay(2000);
  1311. }
  1312. }
  1313. }
  1314. #endif
  1315. #ifdef _GxBitmaps3c128x296_H_
  1316. void drawBitmaps3c128x296()
  1317. {
  1318. #if !defined(__AVR)
  1319. bitmap_pair bitmap_pairs[] =
  1320. {
  1321. {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1322. {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1323. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1324. };
  1325. #else
  1326. bitmap_pair bitmap_pairs[] =
  1327. {
  1328. //{Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1329. //{Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1330. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1331. };
  1332. #endif
  1333. if ((display.epd2.WIDTH == 128) && (display.epd2.HEIGHT == 296) && display.epd2.hasColor)
  1334. {
  1335. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1336. {
  1337. display.firstPage();
  1338. do
  1339. {
  1340. display.fillScreen(GxEPD_WHITE);
  1341. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, 128, 296, GxEPD_BLACK);
  1342. if (bitmap_pairs[i].red == WS_Bitmap3c128x296_red)
  1343. {
  1344. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, 128, 296, GxEPD_RED);
  1345. }
  1346. else display.drawBitmap(0, 0, bitmap_pairs[i].red, 128, 296, GxEPD_RED);
  1347. }
  1348. while (display.nextPage());
  1349. delay(2000);
  1350. }
  1351. }
  1352. }
  1353. #endif
  1354. #ifdef _GxBitmaps3c176x264_H_
  1355. void drawBitmaps3c176x264()
  1356. {
  1357. bitmap_pair bitmap_pairs[] =
  1358. {
  1359. {Bitmap3c176x264_black, Bitmap3c176x264_red}
  1360. };
  1361. if (display.epd2.panel == GxEPD2::GDEW027C44)
  1362. {
  1363. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1364. {
  1365. display.firstPage();
  1366. do
  1367. {
  1368. display.fillScreen(GxEPD_WHITE);
  1369. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1370. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1371. }
  1372. while (display.nextPage());
  1373. delay(2000);
  1374. }
  1375. }
  1376. }
  1377. #endif
  1378. #ifdef _GxBitmaps3c400x300_H_
  1379. void drawBitmaps3c400x300()
  1380. {
  1381. #if !defined(__AVR)
  1382. bitmap_pair bitmap_pairs[] =
  1383. {
  1384. {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
  1385. {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
  1386. {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
  1387. };
  1388. #else
  1389. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1390. #endif
  1391. if (display.epd2.panel == GxEPD2::GDEW042Z15)
  1392. {
  1393. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1394. {
  1395. display.firstPage();
  1396. do
  1397. {
  1398. display.fillScreen(GxEPD_WHITE);
  1399. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1400. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1401. }
  1402. while (display.nextPage());
  1403. delay(2000);
  1404. }
  1405. }
  1406. }
  1407. #endif
  1408. #ifdef _GxBitmaps3c800x480_H_
  1409. void drawBitmaps3c800x480()
  1410. {
  1411. #if !defined(__AVR)
  1412. bitmap_pair bitmap_pairs[] =
  1413. {
  1414. {Bitmap3c800x480_1_black, Bitmap3c800x480_1_red}
  1415. };
  1416. #else
  1417. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1418. #endif
  1419. if (display.epd2.panel == GxEPD2::GDEW075Z08)
  1420. {
  1421. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1422. {
  1423. display.firstPage();
  1424. do
  1425. {
  1426. display.fillScreen(GxEPD_WHITE);
  1427. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1428. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1429. }
  1430. while (display.nextPage());
  1431. delay(2000);
  1432. }
  1433. }
  1434. }
  1435. #endif
  1436. #ifdef _GxBitmaps3c880x528_H_
  1437. void drawBitmaps3c880x528()
  1438. {
  1439. #if !defined(__AVR)
  1440. bitmap_pair bitmap_pairs[] =
  1441. {
  1442. {Bitmap3c880x528_black, Bitmap3c880x528_red}
  1443. };
  1444. #else
  1445. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1446. #endif
  1447. if (display.epd2.panel == GxEPD2::GDEH075Z90)
  1448. {
  1449. bool m = display.mirror(true);
  1450. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1451. {
  1452. display.firstPage();
  1453. do
  1454. {
  1455. display.fillScreen(GxEPD_WHITE);
  1456. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, 880, 528, GxEPD_BLACK);
  1457. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, 880, 528, GxEPD_RED);
  1458. }
  1459. while (display.nextPage());
  1460. delay(2000);
  1461. }
  1462. display.mirror(m);
  1463. }
  1464. }
  1465. #endif
  1466. #if defined(_WS_Bitmaps7c192x143_H_)
  1467. void drawBitmaps7c192x143()
  1468. {
  1469. if (display.epd2.panel == GxEPD2::ACeP565)
  1470. {
  1471. display.drawNative(WS_Bitmap7c192x143, 0, (display.epd2.WIDTH - 192) / 2, (display.epd2.HEIGHT - 143) / 2, 192, 143, false, false, true);
  1472. delay(5000);
  1473. }
  1474. }
  1475. #endif
  1476. void draw7colors()
  1477. {
  1478. display.setRotation(0);
  1479. uint16_t h = display.height() / 7;
  1480. display.firstPage();
  1481. do
  1482. {
  1483. display.fillRect(0, 0, display.width(), h, GxEPD_BLACK);
  1484. display.fillRect(0, h, display.width(), h, GxEPD_WHITE);
  1485. display.fillRect(0, 2 * h, display.width(), h, GxEPD_GREEN);
  1486. display.fillRect(0, 3 * h, display.width(), h, GxEPD_BLUE);
  1487. display.fillRect(0, 4 * h, display.width(), h, GxEPD_RED);
  1488. display.fillRect(0, 5 * h, display.width(), h, GxEPD_YELLOW);
  1489. display.fillRect(0, 6 * h, display.width(), h, GxEPD_ORANGE);
  1490. }
  1491. while (display.nextPage());
  1492. }
  1493. void draw7colorlines()
  1494. {
  1495. display.setRotation(0);
  1496. uint16_t h = 2;
  1497. display.firstPage();
  1498. do
  1499. {
  1500. uint16_t y = 0;
  1501. do
  1502. {
  1503. display.fillRect(0, y, display.width(), h, GxEPD_BLACK); y += h;
  1504. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1505. display.fillRect(0, y, display.width(), h, GxEPD_GREEN); y += h;
  1506. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1507. display.fillRect(0, y, display.width(), h, GxEPD_BLUE); y += h;
  1508. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1509. display.fillRect(0, y, display.width(), h, GxEPD_RED); y += h;
  1510. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1511. display.fillRect(0, y, display.width(), h, GxEPD_YELLOW); y += h;
  1512. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1513. display.fillRect(0, y, display.width(), h, GxEPD_ORANGE); y += h;
  1514. display.fillRect(0, y, display.width(), h, GxEPD_WHITE); y += h;
  1515. }
  1516. while ((y + 12 * h) < display.height());
  1517. //display.drawPixel(0, y, GxEPD_BLACK); display.drawPixel(10, y, GxEPD_GREEN);
  1518. //display.drawPixel(20, y, GxEPD_BLUE); display.drawPixel(30, y, GxEPD_RED);
  1519. //display.drawPixel(40, y, GxEPD_YELLOW); display.drawPixel(50, y, GxEPD_ORANGE);
  1520. display.fillRect(0, y, 2, 2, GxEPD_BLACK); display.fillRect(10, y, 2, 2, GxEPD_GREEN);
  1521. display.fillRect(20, y, 2, 2, GxEPD_BLUE); display.fillRect(30, y, 2, 2, GxEPD_RED);
  1522. display.fillRect(40, y, 2, 2, GxEPD_YELLOW); display.fillRect(50, y, 2, 2, GxEPD_ORANGE);
  1523. }
  1524. while (display.nextPage());
  1525. }