GxEPD2_WS_ESP32_Driver.ino 42 KB

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