GxEPD2_WS_ESP32_Driver.ino 43 KB

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