GxEPD2_WS_ESP32_Driver.ino 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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. // GxEPD2_WS_ESP32_Driver : GxEPD2_Example variant for Universal e-Paper Raw Panel Driver Board, ESP32 WiFi / Bluetooth Wireless
  12. // https://www.waveshare.com/product/e-paper-esp32-driver-board.htm
  13. // Supporting Arduino Forum Topics:
  14. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  15. // Good Display ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  16. // mapping of Waveshare ESP32 Driver Board
  17. // BUSY -> 25, RST -> 26, DC -> 27, CS-> 15, CLK -> 13, DIN -> 14
  18. // NOTE: this board uses "unusual" SPI pins and requires re-mapping of HW SPI to these pins in SPIClass
  19. // this example shows how this can be done easily
  20. // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  21. // enable or disable GxEPD2_GFX base class
  22. #define ENABLE_GxEPD2_GFX 0
  23. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  24. //#include <GFX.h>
  25. // Note: if you use this with ENABLE_GxEPD2_GFX 1:
  26. // uncomment it in GxEPD2_GFX.h too, or add #include <GFX.h> before any #include <GxEPD2_GFX.h>
  27. #include <GxEPD2_BW.h>
  28. #include <GxEPD2_3C.h>
  29. #include <Fonts/FreeMonoBold9pt7b.h>
  30. // select the display class (only one), matching the kind of display panel
  31. #define GxEPD2_DISPLAY_CLASS GxEPD2_BW
  32. //#define GxEPD2_DISPLAY_CLASS GxEPD2_3C
  33. //#define GxEPD2_DISPLAY_CLASS GxEPD2_7C
  34. // select the display driver class (only one) for your panel
  35. //#define GxEPD2_DRIVER_CLASS GxEPD2_102 // GxEPD2_102 80x128, UC8175
  36. //#define GxEPD2_DRIVER_CLASS GxEPD2_154 // GDEP015OC1 200x200, IL3829, no longer available
  37. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_D67 // GDEH0154D67 200x200, SSD1681
  38. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_T8 // GDEW0154T8 152x152, UC8151 (IL0373)
  39. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_M09 // GDEW0154M09 200x200, JD79653A
  40. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_M10 // GDEW0154M10 152x152, UC8151D
  41. //#define GxEPD2_DRIVER_CLASS GxEPD2_213 // GDE0213B1 128x250, IL3895, phased out
  42. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_B72 // GDEH0213B72 128x250, SSD1675A (IL3897)
  43. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_B73 // GDEH0213B73 128x250, SSD1675B
  44. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_B74 // GDEM0213B74 128x250, SSD1680
  45. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_flex // GDEW0213I5F 104x212, UC8151 (IL0373)
  46. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_M21 // GDEW0213M21 104x212, UC8151 (IL0373)
  47. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_T5D // GDEW0213T5D 104x212, UC8151D
  48. //#define GxEPD2_DRIVER_CLASS GxEPD2_290 // GDEH029A1 128x296, SSD1608 (IL3820)
  49. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T5 // GDEW029T5 128x296, UC8151 (IL0373)
  50. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T5D // GDEW029T5D 128x296, UC8151D
  51. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_I6FD // GDEW029I6FD 128x296, UC8151D
  52. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T94 // GDEM029T94 128x296, SSD1680
  53. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T94_V2 // GDEM029T94 128x296, SSD1680, Waveshare 2.9" V2 variant
  54. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_M06 // GDEW029M06 128x296, UC8151D
  55. //#define GxEPD2_DRIVER_CLASS GxEPD2_260 // GDEW026T0 152x296, UC8151 (IL0373)
  56. //#define GxEPD2_DRIVER_CLASS GxEPD2_260_M01 // GDEW026M01 152x296, UC8151 (IL0373)
  57. //#define GxEPD2_DRIVER_CLASS GxEPD2_270 // GDEW027W3 176x264, EK79652 (IL91874)
  58. //#define GxEPD2_DRIVER_CLASS GxEPD2_371 // GDEW0371W7 240x416, UC8171 (IL0324)
  59. //#define GxEPD2_DRIVER_CLASS GxEPD2_370_TC1 // ED037TC1 280x480, SSD1677, Waveshare 3.7"
  60. //#define GxEPD2_DRIVER_CLASS GxEPD2_420 // GDEW042T2 400x300, UC8176 (IL0398)
  61. //#define GxEPD2_DRIVER_CLASS GxEPD2_420_M01 // GDEW042M01 400x300, UC8176 (IL0398)
  62. //#define GxEPD2_DRIVER_CLASS GxEPD2_583 // GDEW0583T7 600x448, UC8179 (IL0371)
  63. //#define GxEPD2_DRIVER_CLASS GxEPD2_583_T8 // GDEW0583T8 648x480, GD7965
  64. //#define GxEPD2_DRIVER_CLASS GxEPD2_750 // GDEW075T8 640x384, UC8179 (IL0371)
  65. //#define GxEPD2_DRIVER_CLASS GxEPD2_750_T7 // GDEW075T7 800x480, GD7965
  66. //#define GxEPD2_DRIVER_CLASS GxEPD2_1160_T91 // GDEH116T91 960x640, SSD1677
  67. //#define GxEPD2_DRIVER_CLASS GxEPD2_1248 // GDEW1248T3 1304x984, UC8179
  68. // 3-color e-papers
  69. //#define GxEPD2_DRIVER_CLASS GxEPD2_154c // GDEW0154Z04 200x200, IL0376F, no longer available
  70. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_Z90c // GDEH0154Z90 200x200, SSD1681
  71. //#define GxEPD2_DRIVER_CLASS GxEPD2_213c // GDEW0213Z16 104x212, UC8151 (IL0373)
  72. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_Z19c // GDEW0213Z19 104x212, UC8151D
  73. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_Z98c // GDEY0213Z98 122x250, SSD1680
  74. //#define GxEPD2_DRIVER_CLASS GxEPD2_290c // GDEW029Z10 128x296, UC8151 (IL0373)
  75. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_Z13c // GDEH029Z13 128x296, UC8151D
  76. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_C90c // GDEM029C90 128x296, SSD1680
  77. //#define GxEPD2_DRIVER_CLASS GxEPD2_266c // GDEY0266Z90 152x296, SSD1680
  78. //#define GxEPD2_DRIVER_CLASS GxEPD2_270c // GDEW027C44 176x264, IL91874
  79. //#define GxEPD2_DRIVER_CLASS GxEPD2_420c // GDEW042Z15 400x300, UC8176 (IL0398)
  80. //#define GxEPD2_DRIVER_CLASS GxEPD2_420c_Z21 // GDEQ042Z21 400x300, UC8276
  81. //#define GxEPD2_DRIVER_CLASS GxEPD2_583c // GDEW0583Z21 600x448, UC8179 (IL0371)
  82. //#define GxEPD2_DRIVER_CLASS GxEPD2_583c_Z83 // GDEW0583Z83 648x480, GD7965
  83. //#define GxEPD2_DRIVER_CLASS GxEPD2_750c // GDEW075Z09 640x384, UC8179 (IL0371)
  84. //#define GxEPD2_DRIVER_CLASS GxEPD2_750c_Z08 // GDEW075Z08 800x480, GD7965
  85. //#define GxEPD2_DRIVER_CLASS GxEPD2_750c_Z90 // GDEH075Z90 880x528, SSD1677
  86. // 7-color e-paper
  87. //#define GxEPD2_DRIVER_CLASS GxEPD2_565c // Waveshare 5.65" 7-color (3C graphics)
  88. // somehow there should be an easier way to do this
  89. #define GxEPD2_BW_IS_GxEPD2_BW true
  90. #define GxEPD2_3C_IS_GxEPD2_3C true
  91. #define GxEPD2_7C_IS_GxEPD2_7C true
  92. #define GxEPD2_1248_IS_GxEPD2_1248 true
  93. #define IS_GxEPD(c, x) (c##x)
  94. #define IS_GxEPD2_BW(x) IS_GxEPD(GxEPD2_BW_IS_, x)
  95. #define IS_GxEPD2_3C(x) IS_GxEPD(GxEPD2_3C_IS_, x)
  96. #define IS_GxEPD2_7C(x) IS_GxEPD(GxEPD2_7C_IS_, x)
  97. #define IS_GxEPD2_1248(x) IS_GxEPD(GxEPD2_1248_IS_, x)
  98. #if defined(ESP32)
  99. #define MAX_DISPLAY_BUFFER_SIZE 65536ul // e.g.
  100. #if IS_GxEPD2_BW(GxEPD2_DISPLAY_CLASS)
  101. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  102. #elif IS_GxEPD2_3C(GxEPD2_DISPLAY_CLASS)
  103. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  104. #elif IS_GxEPD2_7C(GxEPD2_DISPLAY_CLASS)
  105. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2))
  106. #endif
  107. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=*/ 15, /*DC=*/ 27, /*RST=*/ 26, /*BUSY=*/ 25));
  108. #endif
  109. // alternately you can copy the constructor from GxEPD2_display_selection.h of GxEPD_Example to here
  110. // and adapt it to the ESP32 Driver wiring, e.g.
  111. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=*/ 15, /*DC=*/ 27, /*RST=*/ 26, /*BUSY=*/ 25)); // GDEH0154D67
  112. // comment out unused bitmaps to reduce code space used
  113. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  114. #include "bitmaps/Bitmaps104x212.h" // 2.13" b/w flexible GDEW0213I5F
  115. #include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  116. #include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  117. #include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  118. #include "bitmaps/Bitmaps400x300.h" // 4.2" b/w
  119. #include "bitmaps/Bitmaps640x384.h" // 7.5" b/w
  120. // 3-color
  121. #include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  122. #include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  123. #include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  124. #include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  125. #include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r
  126. void setup()
  127. {
  128. Serial.begin(115200);
  129. Serial.println();
  130. Serial.println("setup");
  131. display.init(115200); // uses standard SPI pins, e.g. SCK(18), MISO(19), MOSI(23), SS(5)
  132. // *** special handling for Waveshare ESP32 Driver board *** //
  133. // ********************************************************* //
  134. SPI.end(); // release standard SPI pins, e.g. SCK(18), MISO(19), MOSI(23), SS(5)
  135. //SPI: void begin(int8_t sck=-1, int8_t miso=-1, int8_t mosi=-1, int8_t ss=-1);
  136. SPI.begin(13, 12, 14, 15); // map and init SPI pins SCK(13), MISO(12), MOSI(14), SS(15)
  137. // *** end of special handling for Waveshare ESP32 Driver board *** //
  138. // **************************************************************** //
  139. // first update should be full refresh
  140. helloWorld();
  141. delay(1000);
  142. // partial refresh mode can be used to full screen,
  143. // effective if display panel hasFastPartialUpdate
  144. helloFullScreenPartialMode();
  145. delay(1000);
  146. helloArduino();
  147. delay(1000);
  148. helloEpaper();
  149. delay(1000);
  150. showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
  151. delay(1000);
  152. drawBitmaps();
  153. if (display.epd2.hasPartialUpdate)
  154. {
  155. showPartialUpdate();
  156. delay(1000);
  157. } // else // on GDEW0154Z04 only full update available, doesn't look nice
  158. //drawCornerTest();
  159. //showBox(16, 16, 48, 32, false);
  160. //showBox(16, 56, 48, 32, true);
  161. display.powerOff();
  162. deepSleepTest();
  163. Serial.println("setup done");
  164. }
  165. void loop()
  166. {
  167. }
  168. // note for partial update window and setPartialWindow() method:
  169. // partial update window size and position is on byte boundary in physical x direction
  170. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  171. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  172. const char HelloWorld[] = "Hello World!";
  173. const char HelloArduino[] = "Hello Arduino!";
  174. const char HelloEpaper[] = "Hello E-Paper!";
  175. void helloWorld()
  176. {
  177. //Serial.println("helloWorld");
  178. display.setRotation(1);
  179. display.setFont(&FreeMonoBold9pt7b);
  180. display.setTextColor(GxEPD_BLACK);
  181. int16_t tbx, tby; uint16_t tbw, tbh;
  182. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  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. display.setFullWindow();
  187. display.firstPage();
  188. do
  189. {
  190. display.fillScreen(GxEPD_WHITE);
  191. display.setCursor(x, y);
  192. display.print(HelloWorld);
  193. }
  194. while (display.nextPage());
  195. //Serial.println("helloWorld done");
  196. }
  197. void helloWorldForDummies()
  198. {
  199. //Serial.println("helloWorld");
  200. const char text[] = "Hello World!";
  201. // most e-papers have width < height (portrait) as native orientation, especially the small ones
  202. // in GxEPD2 rotation 0 is used for native orientation (most TFT libraries use 0 fix for portrait orientation)
  203. // set rotation to 1 (rotate right 90 degrees) to have enough space on small displays (landscape)
  204. display.setRotation(1);
  205. // select a suitable font in Adafruit_GFX
  206. display.setFont(&FreeMonoBold9pt7b);
  207. // on e-papers black on white is more pleasant to read
  208. display.setTextColor(GxEPD_BLACK);
  209. // Adafruit_GFX has a handy method getTextBounds() to determine the boundary box for a text for the actual font
  210. int16_t tbx, tby; uint16_t tbw, tbh; // boundary box window
  211. display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh); // it works for origin 0, 0, fortunately (negative tby!)
  212. // center bounding box by transposition of origin:
  213. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  214. uint16_t y = ((display.height() - tbh) / 2) - tby;
  215. // full window mode is the initial mode, set it anyway
  216. display.setFullWindow();
  217. // here we use paged drawing, even if the processor has enough RAM for full buffer
  218. // so this can be used with any supported processor board.
  219. // the cost in code overhead and execution time penalty is marginal
  220. // tell the graphics class to use paged drawing mode
  221. display.firstPage();
  222. do
  223. {
  224. // this part of code is executed multiple times, as many as needed,
  225. // in case of full buffer it is executed once
  226. // IMPORTANT: each iteration needs to draw the same, to avoid strange effects
  227. // use a copy of values that might change, don't read e.g. from analog or pins in the loop!
  228. display.fillScreen(GxEPD_WHITE); // set the background to white (fill the buffer with value for white)
  229. display.setCursor(x, y); // set the postition to start printing text
  230. display.print(text); // print some text
  231. // end of part executed multiple times
  232. }
  233. // tell the graphics class to transfer the buffer content (page) to the controller buffer
  234. // the graphics class will command the controller to refresh to the screen when the last page has been transferred
  235. // returns true if more pages need be drawn and transferred
  236. // returns false if the last page has been transferred and the screen refreshed for panels without fast partial update
  237. // returns false for panels with fast partial update when the controller buffer has been written once more, to make the differential buffers equal
  238. // (for full buffered with fast partial update the (full) buffer is just transferred again, and false returned)
  239. while (display.nextPage());
  240. //Serial.println("helloWorld done");
  241. }
  242. void helloFullScreenPartialMode()
  243. {
  244. //Serial.println("helloFullScreenPartialMode");
  245. const char fullscreen[] = "full screen update";
  246. const char fpm[] = "fast partial mode";
  247. const char spm[] = "slow partial mode";
  248. const char npm[] = "no partial mode";
  249. display.setPartialWindow(0, 0, display.width(), display.height());
  250. display.setRotation(1);
  251. display.setFont(&FreeMonoBold9pt7b);
  252. display.setTextColor(GxEPD_BLACK);
  253. const char* updatemode;
  254. if (display.epd2.hasFastPartialUpdate)
  255. {
  256. updatemode = fpm;
  257. }
  258. else if (display.epd2.hasPartialUpdate)
  259. {
  260. updatemode = spm;
  261. }
  262. else
  263. {
  264. updatemode = npm;
  265. }
  266. // do this outside of the loop
  267. int16_t tbx, tby; uint16_t tbw, tbh;
  268. // center update text
  269. display.getTextBounds(fullscreen, 0, 0, &tbx, &tby, &tbw, &tbh);
  270. uint16_t utx = ((display.width() - tbw) / 2) - tbx;
  271. uint16_t uty = ((display.height() / 4) - tbh / 2) - tby;
  272. // center update mode
  273. display.getTextBounds(updatemode, 0, 0, &tbx, &tby, &tbw, &tbh);
  274. uint16_t umx = ((display.width() - tbw) / 2) - tbx;
  275. uint16_t umy = ((display.height() * 3 / 4) - tbh / 2) - tby;
  276. // center HelloWorld
  277. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  278. uint16_t hwx = ((display.width() - tbw) / 2) - tbx;
  279. uint16_t hwy = ((display.height() - tbh) / 2) - tby;
  280. display.firstPage();
  281. do
  282. {
  283. display.fillScreen(GxEPD_WHITE);
  284. display.setCursor(hwx, hwy);
  285. display.print(HelloWorld);
  286. display.setCursor(utx, uty);
  287. display.print(fullscreen);
  288. display.setCursor(umx, umy);
  289. display.print(updatemode);
  290. }
  291. while (display.nextPage());
  292. //Serial.println("helloFullScreenPartialMode done");
  293. }
  294. void helloArduino()
  295. {
  296. //Serial.println("helloArduino");
  297. display.setRotation(1);
  298. display.setFont(&FreeMonoBold9pt7b);
  299. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  300. int16_t tbx, tby; uint16_t tbw, tbh;
  301. // align with centered HelloWorld
  302. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  303. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  304. // height might be different
  305. display.getTextBounds(HelloArduino, 0, 0, &tbx, &tby, &tbw, &tbh);
  306. uint16_t y = ((display.height() / 4) - tbh / 2) - tby; // y is base line!
  307. // make the window big enough to cover (overwrite) descenders of previous text
  308. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  309. uint16_t wy = (display.height() / 4) - wh / 2;
  310. display.setPartialWindow(0, wy, display.width(), wh);
  311. display.firstPage();
  312. do
  313. {
  314. display.fillScreen(GxEPD_WHITE);
  315. //display.drawRect(x, y - tbh, tbw, tbh, GxEPD_BLACK);
  316. display.setCursor(x, y);
  317. display.print(HelloArduino);
  318. }
  319. while (display.nextPage());
  320. delay(1000);
  321. //Serial.println("helloArduino done");
  322. }
  323. void helloEpaper()
  324. {
  325. //Serial.println("helloEpaper");
  326. display.setRotation(1);
  327. display.setFont(&FreeMonoBold9pt7b);
  328. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  329. int16_t tbx, tby; uint16_t tbw, tbh;
  330. // align with centered HelloWorld
  331. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  332. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  333. // height might be different
  334. display.getTextBounds(HelloEpaper, 0, 0, &tbx, &tby, &tbw, &tbh);
  335. uint16_t y = (display.height() * 3 / 4) + tbh / 2; // y is base line!
  336. // make the window big enough to cover (overwrite) descenders of previous text
  337. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  338. uint16_t wy = (display.height() * 3 / 4) - wh / 2;
  339. display.setPartialWindow(0, wy, display.width(), wh);
  340. display.firstPage();
  341. do
  342. {
  343. display.fillScreen(GxEPD_WHITE);
  344. display.setCursor(x, y);
  345. display.print(HelloEpaper);
  346. }
  347. while (display.nextPage());
  348. //Serial.println("helloEpaper done");
  349. }
  350. void deepSleepTest()
  351. {
  352. //Serial.println("deepSleepTest");
  353. const char hibernating[] = "hibernating ...";
  354. const char wokeup[] = "woke up";
  355. const char from[] = "from deep sleep";
  356. const char again[] = "again";
  357. display.setRotation(1);
  358. display.setFont(&FreeMonoBold9pt7b);
  359. display.setTextColor(GxEPD_BLACK);
  360. int16_t tbx, tby; uint16_t tbw, tbh;
  361. // center text
  362. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  363. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  364. uint16_t y = ((display.height() - tbh) / 2) - tby;
  365. display.setFullWindow();
  366. display.firstPage();
  367. do
  368. {
  369. display.fillScreen(GxEPD_WHITE);
  370. display.setCursor(x, y);
  371. display.print(hibernating);
  372. }
  373. while (display.nextPage());
  374. display.hibernate();
  375. delay(5000);
  376. display.getTextBounds(wokeup, 0, 0, &tbx, &tby, &tbw, &tbh);
  377. uint16_t wx = (display.width() - tbw) / 2;
  378. uint16_t wy = (display.height() / 3) + tbh / 2; // y is base line!
  379. display.getTextBounds(from, 0, 0, &tbx, &tby, &tbw, &tbh);
  380. uint16_t fx = (display.width() - tbw) / 2;
  381. uint16_t fy = (display.height() * 2 / 3) + tbh / 2; // y is base line!
  382. display.firstPage();
  383. do
  384. {
  385. display.fillScreen(GxEPD_WHITE);
  386. display.setCursor(wx, wy);
  387. display.print(wokeup);
  388. display.setCursor(fx, fy);
  389. display.print(from);
  390. }
  391. while (display.nextPage());
  392. delay(5000);
  393. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  394. uint16_t hx = (display.width() - tbw) / 2;
  395. uint16_t hy = (display.height() / 3) + tbh / 2; // y is base line!
  396. display.getTextBounds(again, 0, 0, &tbx, &tby, &tbw, &tbh);
  397. uint16_t ax = (display.width() - tbw) / 2;
  398. uint16_t ay = (display.height() * 2 / 3) + tbh / 2; // y is base line!
  399. display.firstPage();
  400. do
  401. {
  402. display.fillScreen(GxEPD_WHITE);
  403. display.setCursor(hx, hy);
  404. display.print(hibernating);
  405. display.setCursor(ax, ay);
  406. display.print(again);
  407. }
  408. while (display.nextPage());
  409. display.hibernate();
  410. //Serial.println("deepSleepTest done");
  411. }
  412. void showBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool partial)
  413. {
  414. //Serial.println("showBox");
  415. display.setRotation(1);
  416. if (partial)
  417. {
  418. display.setPartialWindow(x, y, w, h);
  419. }
  420. else
  421. {
  422. display.setFullWindow();
  423. }
  424. display.firstPage();
  425. do
  426. {
  427. display.fillScreen(GxEPD_WHITE);
  428. display.fillRect(x, y, w, h, GxEPD_BLACK);
  429. }
  430. while (display.nextPage());
  431. //Serial.println("showBox done");
  432. }
  433. void drawCornerTest()
  434. {
  435. display.setFullWindow();
  436. display.setFont(&FreeMonoBold9pt7b);
  437. display.setTextColor(GxEPD_BLACK);
  438. for (uint16_t r = 0; r <= 4; r++)
  439. {
  440. display.setRotation(r);
  441. display.firstPage();
  442. do
  443. {
  444. display.fillScreen(GxEPD_WHITE);
  445. display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
  446. display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
  447. display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
  448. display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
  449. display.setCursor(display.width() / 2, display.height() / 2);
  450. display.print(display.getRotation());
  451. }
  452. while (display.nextPage());
  453. delay(2000);
  454. }
  455. }
  456. void showFont(const char name[], const GFXfont* f)
  457. {
  458. display.setFullWindow();
  459. display.setRotation(0);
  460. display.setTextColor(GxEPD_BLACK);
  461. display.firstPage();
  462. do
  463. {
  464. drawFont(name, f);
  465. }
  466. while (display.nextPage());
  467. }
  468. void drawFont(const char name[], const GFXfont* f)
  469. {
  470. //display.setRotation(0);
  471. display.fillScreen(GxEPD_WHITE);
  472. display.setTextColor(GxEPD_BLACK);
  473. display.setFont(f);
  474. display.setCursor(0, 0);
  475. display.println();
  476. display.println(name);
  477. display.println(" !\"#$%&'()*+,-./");
  478. display.println("0123456789:;<=>?");
  479. display.println("@ABCDEFGHIJKLMNO");
  480. display.println("PQRSTUVWXYZ[\\]^_");
  481. if (display.epd2.hasColor)
  482. {
  483. display.setTextColor(GxEPD_RED);
  484. }
  485. display.println("`abcdefghijklmno");
  486. display.println("pqrstuvwxyz{|}~ ");
  487. }
  488. // note for partial update window and setPartialWindow() method:
  489. // partial update window size and position is on byte boundary in physical x direction
  490. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  491. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  492. // showPartialUpdate() purposely uses values that are not multiples of 8 to test this
  493. void showPartialUpdate()
  494. {
  495. // some useful background
  496. helloWorld();
  497. // use asymmetric values for test
  498. uint16_t box_x = 10;
  499. uint16_t box_y = 15;
  500. uint16_t box_w = 70;
  501. uint16_t box_h = 20;
  502. uint16_t cursor_y = box_y + box_h - 6;
  503. float value = 13.95;
  504. uint16_t incr = display.epd2.hasFastPartialUpdate ? 1 : 3;
  505. display.setFont(&FreeMonoBold9pt7b);
  506. display.setTextColor(GxEPD_BLACK);
  507. // show where the update box is
  508. for (uint16_t r = 0; r < 4; r++)
  509. {
  510. display.setRotation(r);
  511. display.setPartialWindow(box_x, box_y, box_w, box_h);
  512. display.firstPage();
  513. do
  514. {
  515. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_BLACK);
  516. //display.fillScreen(GxEPD_BLACK);
  517. }
  518. while (display.nextPage());
  519. delay(2000);
  520. display.firstPage();
  521. do
  522. {
  523. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  524. }
  525. while (display.nextPage());
  526. delay(1000);
  527. }
  528. //return;
  529. // show updates in the update box
  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. for (uint16_t i = 1; i <= 10; i += incr)
  535. {
  536. display.firstPage();
  537. do
  538. {
  539. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  540. display.setCursor(box_x, cursor_y);
  541. display.print(value * i, 2);
  542. }
  543. while (display.nextPage());
  544. delay(500);
  545. }
  546. delay(1000);
  547. display.firstPage();
  548. do
  549. {
  550. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  551. }
  552. while (display.nextPage());
  553. delay(1000);
  554. }
  555. }
  556. void drawBitmaps()
  557. {
  558. display.setFullWindow();
  559. #ifdef _GxBitmaps104x212_H_
  560. drawBitmaps104x212();
  561. #endif
  562. #ifdef _GxBitmaps128x250_H_
  563. drawBitmaps128x250();
  564. #endif
  565. #ifdef _GxBitmaps128x296_H_
  566. drawBitmaps128x296();
  567. #endif
  568. #ifdef _GxBitmaps176x264_H_
  569. drawBitmaps176x264();
  570. #endif
  571. #ifdef _GxBitmaps400x300_H_
  572. drawBitmaps400x300();
  573. #endif
  574. #ifdef _GxBitmaps640x384_H_
  575. drawBitmaps640x384();
  576. #endif
  577. #ifdef _WS_Bitmaps800x600_H_
  578. drawBitmaps800x600();
  579. #endif
  580. // 3-color
  581. #ifdef _GxBitmaps3c104x212_H_
  582. drawBitmaps3c104x212();
  583. #endif
  584. #ifdef _GxBitmaps3c128x296_H_
  585. drawBitmaps3c128x296();
  586. #endif
  587. #ifdef _GxBitmaps3c176x264_H_
  588. drawBitmaps3c176x264();
  589. #endif
  590. #ifdef _GxBitmaps3c400x300_H_
  591. drawBitmaps3c400x300();
  592. #endif
  593. // show these after the specific bitmaps
  594. #ifdef _GxBitmaps200x200_H_
  595. drawBitmaps200x200();
  596. #endif
  597. // 3-color
  598. #ifdef _GxBitmaps3c200x200_H_
  599. drawBitmaps3c200x200();
  600. #endif
  601. }
  602. #ifdef _GxBitmaps200x200_H_
  603. void drawBitmaps200x200()
  604. {
  605. #if defined(__AVR)
  606. const unsigned char* bitmaps[] =
  607. {
  608. logo200x200, first200x200 //, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  609. };
  610. #elif defined(_BOARD_GENERIC_STM32F103C_H_)
  611. const unsigned char* bitmaps[] =
  612. {
  613. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200 //, sixth200x200, senventh200x200, eighth200x200
  614. };
  615. #else
  616. const unsigned char* bitmaps[] =
  617. {
  618. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  619. };
  620. #endif
  621. if ((display.epd2.panel == GxEPD2::GDEP015OC1) || (display.epd2.panel == GxEPD2::GDEH0154D67))
  622. {
  623. bool m = display.mirror(true);
  624. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  625. {
  626. display.firstPage();
  627. do
  628. {
  629. display.fillScreen(GxEPD_WHITE);
  630. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  631. }
  632. while (display.nextPage());
  633. delay(2000);
  634. }
  635. display.mirror(m);
  636. }
  637. //else
  638. {
  639. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  640. display.clearScreen(); // use default for white
  641. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  642. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  643. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  644. {
  645. display.drawImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  646. delay(2000);
  647. }
  648. }
  649. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  650. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  651. {
  652. int16_t x = -60;
  653. int16_t y = -60;
  654. for (uint16_t j = 0; j < 10; j++)
  655. {
  656. display.writeScreenBuffer(); // use default for white
  657. display.writeImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  658. display.refresh(true);
  659. if (display.epd2.hasFastPartialUpdate)
  660. {
  661. // for differential update: set previous buffer equal to current buffer in controller
  662. display.epd2.writeScreenBufferAgain(); // use default for white
  663. display.epd2.writeImageAgain(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  664. }
  665. delay(2000);
  666. x += 40;
  667. y += 40;
  668. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  669. }
  670. if (!display.epd2.hasFastPartialUpdate) break; // comment out for full show
  671. break; // comment out for full show
  672. }
  673. display.writeScreenBuffer(); // use default for white
  674. display.writeImage(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  675. display.writeImage(bitmaps[0], int16_t(int16_t(display.epd2.WIDTH) - 200), int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, mirror_y, true);
  676. display.refresh(true);
  677. delay(2000);
  678. }
  679. #endif
  680. #ifdef _GxBitmaps104x212_H_
  681. void drawBitmaps104x212()
  682. {
  683. #if !defined(__AVR)
  684. const unsigned char* bitmaps[] =
  685. {
  686. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  687. };
  688. #else
  689. const unsigned char* bitmaps[] =
  690. {
  691. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  692. };
  693. #endif
  694. if (display.epd2.panel == GxEPD2::GDEW0213I5F)
  695. {
  696. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  697. {
  698. display.firstPage();
  699. do
  700. {
  701. display.fillScreen(GxEPD_WHITE);
  702. display.drawBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  703. }
  704. while (display.nextPage());
  705. delay(2000);
  706. }
  707. }
  708. }
  709. #endif
  710. #ifdef _GxBitmaps128x250_H_
  711. void drawBitmaps128x250()
  712. {
  713. #if !defined(__AVR)
  714. const unsigned char* bitmaps[] =
  715. {
  716. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  717. };
  718. #else
  719. const unsigned char* bitmaps[] =
  720. {
  721. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  722. };
  723. #endif
  724. if ((display.epd2.panel == GxEPD2::GDE0213B1) || (display.epd2.panel == GxEPD2::GDEH0213B72))
  725. {
  726. bool m = display.mirror(true);
  727. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  728. {
  729. display.firstPage();
  730. do
  731. {
  732. display.fillScreen(GxEPD_WHITE);
  733. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  734. }
  735. while (display.nextPage());
  736. delay(2000);
  737. }
  738. display.mirror(m);
  739. }
  740. }
  741. #endif
  742. #ifdef _GxBitmaps128x296_H_
  743. void drawBitmaps128x296()
  744. {
  745. #if !defined(__AVR)
  746. const unsigned char* bitmaps[] =
  747. {
  748. Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
  749. };
  750. #else
  751. const unsigned char* bitmaps[] =
  752. {
  753. Bitmap128x296_1, logo128x296 //, first128x296, second128x296, third128x296
  754. };
  755. #endif
  756. if (display.epd2.panel == GxEPD2::GDEH029A1)
  757. {
  758. bool m = display.mirror(true);
  759. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  760. {
  761. display.firstPage();
  762. do
  763. {
  764. display.fillScreen(GxEPD_WHITE);
  765. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  766. }
  767. while (display.nextPage());
  768. delay(2000);
  769. }
  770. display.mirror(m);
  771. }
  772. }
  773. #endif
  774. #ifdef _GxBitmaps176x264_H_
  775. void drawBitmaps176x264()
  776. {
  777. #if !defined(__AVR)
  778. const unsigned char* bitmaps[] =
  779. {
  780. Bitmap176x264_1, Bitmap176x264_2, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  781. };
  782. #else
  783. const unsigned char* bitmaps[] =
  784. {
  785. Bitmap176x264_1, Bitmap176x264_2 //, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  786. };
  787. #endif
  788. if (display.epd2.panel == GxEPD2::GDEW027W3)
  789. {
  790. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  791. {
  792. display.firstPage();
  793. do
  794. {
  795. display.fillScreen(GxEPD_WHITE);
  796. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  797. }
  798. while (display.nextPage());
  799. delay(2000);
  800. }
  801. }
  802. }
  803. #endif
  804. #ifdef _GxBitmaps400x300_H_
  805. void drawBitmaps400x300()
  806. {
  807. #if !defined(__AVR)
  808. const unsigned char* bitmaps[] =
  809. {
  810. Bitmap400x300_1, Bitmap400x300_2
  811. };
  812. #else
  813. const unsigned char* bitmaps[] = {}; // not enough code space
  814. #endif
  815. if (display.epd2.panel == GxEPD2::GDEW042T2)
  816. {
  817. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  818. {
  819. display.firstPage();
  820. do
  821. {
  822. display.fillScreen(GxEPD_WHITE);
  823. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  824. }
  825. while (display.nextPage());
  826. delay(2000);
  827. }
  828. }
  829. }
  830. #endif
  831. #ifdef _GxBitmaps640x384_H_
  832. void drawBitmaps640x384()
  833. {
  834. #if !defined(__AVR)
  835. const unsigned char* bitmaps[] =
  836. {
  837. Bitmap640x384_1, Bitmap640x384_2
  838. };
  839. #else
  840. const unsigned char* bitmaps[] = {}; // not enough code space
  841. #endif
  842. if ((display.epd2.panel == GxEPD2::GDEW075T8) || (display.epd2.panel == GxEPD2::GDEW075Z09))
  843. {
  844. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  845. {
  846. display.firstPage();
  847. do
  848. {
  849. display.fillScreen(GxEPD_WHITE);
  850. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  851. }
  852. while (display.nextPage());
  853. delay(2000);
  854. }
  855. }
  856. }
  857. #endif
  858. #ifdef _WS_Bitmaps800x600_H_
  859. void drawBitmaps800x600()
  860. {
  861. #if defined(ESP8266) || defined(ESP32)
  862. if (display.epd2.panel == GxEPD2::ED060SCT)
  863. {
  864. // Serial.print("sizeof(WS_zoo_800x600) is "); Serial.println(sizeof(WS_zoo_800x600));
  865. display.drawNative(WS_zoo_800x600, 0, 0, 0, 800, 600, false, false, true);
  866. delay(2000);
  867. // Serial.print("sizeof(WS_pic_1200x825) is "); Serial.println(sizeof(WS_pic_1200x825));
  868. // display.drawNative((const uint8_t*)WS_pic_1200x825, 0, 0, 0, 1200, 825, false, false, true);
  869. // delay(2000);
  870. // Serial.print("sizeof(WS_acaa_1024x731) is "); Serial.println(sizeof(WS_acaa_1024x731));
  871. // display.drawNative(WS_acaa_1024x731, 0, 0, 0, 1024, 731, false, false, true);
  872. // delay(2000);
  873. }
  874. #endif
  875. }
  876. #endif
  877. struct bitmap_pair
  878. {
  879. const unsigned char* black;
  880. const unsigned char* red;
  881. };
  882. #ifdef _GxBitmaps3c200x200_H_
  883. void drawBitmaps3c200x200()
  884. {
  885. bitmap_pair bitmap_pairs[] =
  886. {
  887. //{Bitmap3c200x200_black, Bitmap3c200x200_red},
  888. {WS_Bitmap3c200x200_black, WS_Bitmap3c200x200_red}
  889. };
  890. if (display.epd2.panel == GxEPD2::GDEW0154Z04)
  891. {
  892. display.firstPage();
  893. do
  894. {
  895. display.fillScreen(GxEPD_WHITE);
  896. // Bitmap3c200x200_black has 2 bits per pixel
  897. // taken from Adafruit_GFX.cpp, modified
  898. int16_t byteWidth = (display.epd2.WIDTH + 7) / 8; // Bitmap scanline pad = whole byte
  899. uint8_t byte = 0;
  900. for (int16_t j = 0; j < display.epd2.HEIGHT; j++)
  901. {
  902. for (int16_t i = 0; i < display.epd2.WIDTH; i++)
  903. {
  904. if (i & 3) byte <<= 2;
  905. else
  906. {
  907. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  908. byte = pgm_read_byte(&Bitmap3c200x200_black[j * byteWidth * 2 + i / 4]);
  909. #else
  910. byte = Bitmap3c200x200_black[j * byteWidth * 2 + i / 4];
  911. #endif
  912. }
  913. if (!(byte & 0x80))
  914. {
  915. display.drawPixel(i, j, GxEPD_BLACK);
  916. }
  917. }
  918. }
  919. display.drawInvertedBitmap(0, 0, Bitmap3c200x200_red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  920. }
  921. while (display.nextPage());
  922. delay(2000);
  923. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  924. {
  925. display.firstPage();
  926. do
  927. {
  928. display.fillScreen(GxEPD_WHITE);
  929. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  930. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  931. }
  932. while (display.nextPage());
  933. delay(2000);
  934. }
  935. }
  936. if (display.epd2.hasColor)
  937. {
  938. display.clearScreen(); // use default for white
  939. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  940. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  941. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  942. {
  943. display.drawImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  944. delay(2000);
  945. }
  946. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  947. {
  948. int16_t x = -60;
  949. int16_t y = -60;
  950. for (uint16_t j = 0; j < 10; j++)
  951. {
  952. display.writeScreenBuffer(); // use default for white
  953. display.writeImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  954. display.refresh();
  955. delay(1000);
  956. x += 40;
  957. y += 40;
  958. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  959. }
  960. }
  961. display.writeScreenBuffer(); // use default for white
  962. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, 0, 0, 200, 200, false, false, true);
  963. 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);
  964. display.refresh();
  965. delay(2000);
  966. }
  967. }
  968. #endif
  969. #ifdef _GxBitmaps3c104x212_H_
  970. void drawBitmaps3c104x212()
  971. {
  972. #if !defined(__AVR)
  973. bitmap_pair bitmap_pairs[] =
  974. {
  975. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  976. {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  977. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  978. };
  979. #else
  980. bitmap_pair bitmap_pairs[] =
  981. {
  982. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  983. //{Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  984. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  985. };
  986. #endif
  987. if (display.epd2.panel == GxEPD2::GDEW0213Z16)
  988. {
  989. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  990. {
  991. display.firstPage();
  992. do
  993. {
  994. display.fillScreen(GxEPD_WHITE);
  995. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  996. if (bitmap_pairs[i].red == WS_Bitmap3c104x212_red)
  997. {
  998. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  999. }
  1000. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1001. }
  1002. while (display.nextPage());
  1003. delay(2000);
  1004. }
  1005. }
  1006. }
  1007. #endif
  1008. #ifdef _GxBitmaps3c128x296_H_
  1009. void drawBitmaps3c128x296()
  1010. {
  1011. #if !defined(__AVR)
  1012. bitmap_pair bitmap_pairs[] =
  1013. {
  1014. {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1015. {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1016. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1017. };
  1018. #else
  1019. bitmap_pair bitmap_pairs[] =
  1020. {
  1021. //{Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1022. //{Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1023. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1024. };
  1025. #endif
  1026. if (display.epd2.panel == GxEPD2::GDEW029Z10)
  1027. {
  1028. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1029. {
  1030. display.firstPage();
  1031. do
  1032. {
  1033. display.fillScreen(GxEPD_WHITE);
  1034. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1035. if (bitmap_pairs[i].red == WS_Bitmap3c128x296_red)
  1036. {
  1037. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1038. }
  1039. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1040. }
  1041. while (display.nextPage());
  1042. delay(2000);
  1043. }
  1044. }
  1045. }
  1046. #endif
  1047. #ifdef _GxBitmaps3c176x264_H_
  1048. void drawBitmaps3c176x264()
  1049. {
  1050. bitmap_pair bitmap_pairs[] =
  1051. {
  1052. {Bitmap3c176x264_black, Bitmap3c176x264_red}
  1053. };
  1054. if (display.epd2.panel == GxEPD2::GDEW027C44)
  1055. {
  1056. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1057. {
  1058. display.firstPage();
  1059. do
  1060. {
  1061. display.fillScreen(GxEPD_WHITE);
  1062. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1063. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1064. }
  1065. while (display.nextPage());
  1066. delay(2000);
  1067. }
  1068. }
  1069. }
  1070. #endif
  1071. #ifdef _GxBitmaps3c400x300_H_
  1072. void drawBitmaps3c400x300()
  1073. {
  1074. #if !defined(__AVR)
  1075. bitmap_pair bitmap_pairs[] =
  1076. {
  1077. {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
  1078. {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
  1079. {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
  1080. };
  1081. #else
  1082. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1083. #endif
  1084. if (display.epd2.panel == GxEPD2::GDEW042Z15)
  1085. {
  1086. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1087. {
  1088. display.firstPage();
  1089. do
  1090. {
  1091. display.fillScreen(GxEPD_WHITE);
  1092. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1093. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1094. }
  1095. while (display.nextPage());
  1096. delay(2000);
  1097. }
  1098. }
  1099. }
  1100. #endif