GxEPD2_Example.ino 45 KB

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