GxEPD2_Example.ino 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  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: these e-papers require 3.3V supply AND data lines!
  3. //
  4. // Display Library based on Demo Example from Good Display: http://www.e-paper-display.com/download_list/downloadcategoryid=34&isMode=false.html
  5. //
  6. // Author: Jean-Marc Zingg
  7. //
  8. // Version: see library.properties
  9. //
  10. // Library: https://github.com/ZinggJM/GxEPD2
  11. // Supporting Arduino Forum Topics:
  12. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  13. // Good Dispay ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  14. // mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
  15. // BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
  16. // NOTE: connect 4.7k pull-down from D8 to GND if your board or shield has level converters
  17. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case, or 4k7 pull-down
  18. // mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
  19. // BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  20. // NOTE: connect 4.7k pull-down from GPIO15 to GND if your board or shield has level converters
  21. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case, or 4k7 pull-down
  22. // mapping of Waveshare e-Paper ESP8266 Driver Board
  23. // BUSY -> GPIO16, RST -> GPIO5, DC -> GPIO4, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  24. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case
  25. // mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
  26. // NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
  27. // BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V
  28. // new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
  29. // BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
  30. // mapping suggestion for AVR, UNO, NANO etc.
  31. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11
  32. // mapping of Waveshare Universal e-Paper Raw Panel Driver Shield for Arduino / NUCLEO
  33. // BUSY -> 7, RST -> 8, DC -> 9, CS-> 10, CLK -> 13, DIN -> 11
  34. // mapping suggestion for Arduino MEGA
  35. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 53, CLK -> 52, DIN -> 51
  36. // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  37. // enable or disable GxEPD2_GFX base class
  38. #define ENABLE_GxEPD2_GFX 0
  39. #include <GxEPD2_BW.h>
  40. #include <GxEPD2_3C.h>
  41. #include <Fonts/FreeMonoBold9pt7b.h>
  42. #if defined (ESP8266)
  43. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  44. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  45. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDE0213B1, phased out
  46. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0213B72
  47. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0213I5F
  48. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  49. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW029T5
  50. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  51. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  52. // can use only half buffer size
  53. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  54. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  55. // 3-color e-papers
  56. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  57. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  58. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  59. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  60. // can use only half buffer size
  61. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  62. // can use only quarter buffer size
  63. //GxEPD2_3C < GxEPD2_583c, GxEPD2_583c::HEIGHT / 4 > display(GxEPD2_583c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  64. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  65. // grey levels parallel IF e-papers on Waveshare e-Paper IT8951 Driver HAT
  66. // HRDY -> 4, RST -> 2, CS -> SS(15), SCK -> SCK(14), MOSI -> MOSI(D7(13)), MISO -> MISO(D6(12)), GND -> GND, 5V -> 5V
  67. // note: 5V supply needs to be exact and strong; 5V pin of USB powered Wemos D1 mini doesn't work!
  68. //GxEPD2_BW<GxEPD2_it60, GxEPD2_it60::HEIGHT / 8> display(GxEPD2_it60(/*CS=5*/ SS, /*DC=*/ 0, /*RST=*/ 2, /*BUSY=*/ 4));
  69. // ***** for mapping of Waveshare e-Paper ESP8266 Driver Board *****
  70. // select one , can use full buffer size (full HEIGHT)
  71. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  72. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDE0213B1, phased out
  73. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEH0213B72
  74. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW0213I5F
  75. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  76. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW029T5
  77. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  78. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  79. // can use only half buffer size
  80. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  81. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  82. // 3-color e-papers
  83. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  84. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  85. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  86. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  87. // can use only half buffer size
  88. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  89. // can use only quarter buffer size
  90. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  91. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  92. #endif
  93. #if defined(ESP32)
  94. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  95. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  96. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDE0213B1, phased out
  97. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B72
  98. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0213I5F
  99. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  100. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW029T5
  101. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  102. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  103. //GxEPD2_BW<GxEPD2_583, GxEPD2_583::HEIGHT> display(GxEPD2_583(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  104. //GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  105. // 3-color e-papers
  106. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  107. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  108. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  109. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  110. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT> display(GxEPD2_420c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  111. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT> display(GxEPD2_583c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  112. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT> display(GxEPD2_750c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  113. // grey levels parallel IF e-papers on Waveshare e-Paper IT8951 Driver HAT
  114. // HRDY -> 4, RST -> 16, CS -> SS(5), SCK -> SCK(18), MOSI -> MOSI(23), MISO -> MISO(19), GND -> GND, 5V -> 5V
  115. // note: 5V supply needs to be exact and strong; 5V over diode from USB (e.g. Wemos D1 mini) doesn't work!
  116. //GxEPD2_BW<GxEPD2_it60, GxEPD2_it60::HEIGHT> display(GxEPD2_it60(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  117. #endif
  118. #if defined(_BOARD_GENERIC_STM32F103C_H_)
  119. #define MAX_DISPAY_BUFFER_SIZE 15000ul // ~15k is a good compromise
  120. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  121. // select one and adapt to your mapping
  122. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  123. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDE0213B1, phased out
  124. //GxEPD2_BW<GxEPD2_213_B72, MAX_HEIGHT(GxEPD2_213_B72)> display(GxEPD2_213_B72(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH0213B72
  125. //GxEPD2_BW<GxEPD2_213_flex, MAX_HEIGHT(GxEPD2_213_flex)> display(GxEPD2_213_flex(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0213I5F
  126. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  127. //GxEPD2_BW<GxEPD2_290_T5, MAX_HEIGHT(GxEPD2_290_T5)> display(GxEPD2_290_T5(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW029T5
  128. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  129. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  130. //GxEPD2_BW<GxEPD2_583, MAX_HEIGHT(GxEPD2_583)> display(GxEPD2_583(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  131. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  132. // 3-color e-papers
  133. #define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  134. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  135. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  136. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  137. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  138. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  139. //GxEPD2_3C<GxEPD2_583c, MAX_HEIGHT_3C(GxEPD2_583c)> display(GxEPD2_583c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  140. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  141. #endif
  142. #if defined(__AVR)
  143. #define MAX_DISPAY_BUFFER_SIZE 800 //
  144. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  145. // select one and adapt to your mapping
  146. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  147. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7)); // GDE0213B1, phased out
  148. //GxEPD2_BW<GxEPD2_213_B72, MAX_HEIGHT(GxEPD2_213_B72)> display(GxEPD2_213_B72(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7)); // GDEH0213B72
  149. //GxEPD2_BW<GxEPD2_213_flex, MAX_HEIGHT(GxEPD2_213_flex)> display(GxEPD2_213_flex(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7)); // GDEW0213I5F
  150. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  151. //GxEPD2_BW<GxEPD2_290_T5, MAX_HEIGHT(GxEPD2_290_T5)> display(GxEPD2_290_T5(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7)); // GDEW029T5
  152. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  153. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  154. //GxEPD2_BW<GxEPD2_583, MAX_HEIGHT(GxEPD2_583)> display(GxEPD2_583(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  155. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  156. // 3-color e-papers
  157. #define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  158. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  159. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  160. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  161. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  162. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  163. //GxEPD2_3C<GxEPD2_583c, MAX_HEIGHT_3C(GxEPD2_583c)> display(GxEPD2_583c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  164. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  165. // ***** for mapping of Waveshare Universal e-Paper Raw Panel Driver Shield for Arduino / NUCLEO *****
  166. // the RST line is not connected through level converter, but has a pull up resistor and a pull down diode to the Arduino pin; this is safe for 5V Arduino
  167. // NOTE: the 11-pinholes for pin connectors are not through level converter, and the VCC pin is ~4.2V, only FCP connector pins are through level converter
  168. // NOTE: the VCC pin on the 11-pinholes for pin connectors shouldn't be used, it seems to get back-fed from Arduino data pins through protection diodes of the level converter
  169. // NOTE: the VCC pin should be fed from Arduino 5V pin for use on any 5V Arduino (did they forget to add this connection or add a jumper?)
  170. // select one and adapt to your mapping
  171. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  172. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7)); // GDE0213B1, phased out
  173. //GxEPD2_BW<GxEPD2_213_B72, MAX_HEIGHT(GxEPD2_213_B72)> display(GxEPD2_213_B72(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7)); // GDEH0213B72
  174. //GxEPD2_BW<GxEPD2_213_flex, MAX_HEIGHT(GxEPD2_213_flex)> display(GxEPD2_213_flex(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7)); // GDEW0213I5F
  175. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  176. //GxEPD2_BW<GxEPD2_290_T5, MAX_HEIGHT(GxEPD2_290_T5)> display(GxEPD2_290_T5(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7)); // GDEW029T5
  177. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  178. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  179. //GxEPD2_BW<GxEPD2_583, MAX_HEIGHT(GxEPD2_583)> display(GxEPD2_583(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  180. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  181. // 3-color e-papers
  182. #define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  183. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  184. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  185. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  186. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  187. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  188. //GxEPD2_3C<GxEPD2_583c, MAX_HEIGHT_3C(GxEPD2_583c)> display(GxEPD2_583c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  189. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
  190. #endif
  191. #include "GxEPD2_boards_added.h"
  192. //#include "GxEPD2_more_boards_added.h" // private
  193. #if !defined(__AVR) && !defined(_BOARD_GENERIC_STM32F103C_H_)
  194. // comment out unused bitmaps to reduce code space used
  195. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  196. #include "bitmaps/Bitmaps104x212.h" // 2.13" b/w flexible GDEW0213I5F
  197. #include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  198. #include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  199. #include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  200. #include "bitmaps/Bitmaps400x300.h" // 4.2" b/w
  201. #include "bitmaps/Bitmaps640x384.h" // 7.5" b/w
  202. // 3-color
  203. #include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  204. #include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  205. #include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  206. #include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  207. #include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r
  208. #if defined(ESP8266) || defined(ESP32)
  209. #include "bitmaps/WS_Bitmaps800x600.h" // 6.0" grey
  210. #endif
  211. #else
  212. // select only one to fit in code space
  213. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  214. //#include "bitmaps/Bitmaps104x212.h" // 2.13" b/w flexible GDEW0213I5F
  215. //#include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  216. //#include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  217. //#include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  218. ////#include "bitmaps/Bitmaps400x300.h" // 4.2" b/w // not enough code space
  219. ////#include "bitmaps/Bitmaps640x384.h" // 7.5" b/w // not enough code space
  220. // 3-color
  221. //#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  222. //#include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  223. //#include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  224. //#include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  225. ////#include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r // not enough code space
  226. #endif
  227. void setup()
  228. {
  229. Serial.begin(115200);
  230. Serial.println();
  231. Serial.println("setup");
  232. delay(100);
  233. display.init(115200);
  234. // first update should be full refresh
  235. helloWorld();
  236. delay(1000);
  237. // partial refresh mode can be used to full screen,
  238. // effective if display panel hasFastPartialUpdate
  239. helloFullScreenPartialMode();
  240. delay(1000);
  241. helloArduino();
  242. delay(1000);
  243. helloEpaper();
  244. delay(1000);
  245. //helloValue(123.9, 1);
  246. //delay(1000);
  247. showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
  248. delay(1000);
  249. drawBitmaps();
  250. if (display.epd2.hasPartialUpdate)
  251. {
  252. showPartialUpdate();
  253. delay(1000);
  254. } // else // on GDEW0154Z04 only full update available, doesn't look nice
  255. //drawCornerTest();
  256. //showBox(16, 16, 48, 32, false);
  257. //showBox(16, 56, 48, 32, true);
  258. display.powerOff();
  259. deepSleepTest();
  260. Serial.println("setup done");
  261. }
  262. void loop()
  263. {
  264. }
  265. // note for partial update window and setPartialWindow() method:
  266. // partial update window size and position is on byte boundary in physical x direction
  267. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  268. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  269. const char HelloWorld[] = "Hello World!";
  270. const char HelloArduino[] = "Hello Arduino!";
  271. const char HelloEpaper[] = "Hello E-Paper!";
  272. void helloWorld()
  273. {
  274. //Serial.println("helloWorld");
  275. display.setRotation(1);
  276. display.setFont(&FreeMonoBold9pt7b);
  277. display.setTextColor(GxEPD_BLACK);
  278. int16_t tbx, tby; uint16_t tbw, tbh;
  279. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  280. // center bounding box by transposition of origin:
  281. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  282. uint16_t y = ((display.height() - tbh) / 2) - tby;
  283. display.setFullWindow();
  284. display.firstPage();
  285. do
  286. {
  287. display.fillScreen(GxEPD_WHITE);
  288. display.setCursor(x, y);
  289. display.print(HelloWorld);
  290. }
  291. while (display.nextPage());
  292. //Serial.println("helloWorld done");
  293. }
  294. void helloWorldForDummies()
  295. {
  296. //Serial.println("helloWorld");
  297. const char text[] = "Hello World!";
  298. // most e-papers have width < height (portrait) as native orientation, especially the small ones
  299. // in GxEPD2 rotation 0 is used for native orientation (most TFT libraries use 0 fix for portrait orientation)
  300. // set rotation to 1 (rotate right 90 degrees) to have enough space on small displays (landscape)
  301. display.setRotation(1);
  302. // select a suitable font in Adafruit_GFX
  303. display.setFont(&FreeMonoBold9pt7b);
  304. // on e-papers black on white is more pleasant to read
  305. display.setTextColor(GxEPD_BLACK);
  306. // Adafruit_GFX has a handy method getTextBounds() to determine the boundary box for a text for the actual font
  307. int16_t tbx, tby; uint16_t tbw, tbh; // boundary box window
  308. display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh); // it works for origin 0, 0, fortunately (negative tby!)
  309. // center bounding box by transposition of origin:
  310. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  311. uint16_t y = ((display.height() - tbh) / 2) - tby;
  312. // full window mode is the initial mode, set it anyway
  313. display.setFullWindow();
  314. // here we use paged drawing, even if the processor has enough RAM for full buffer
  315. // so this can be used with any supported processor board.
  316. // the cost in code overhead and execution time penalty is marginal
  317. // tell the graphics class to use paged drawing mode
  318. display.firstPage();
  319. do
  320. {
  321. // this part of code is executed multiple times, as many as needed,
  322. // in case of full buffer it is executed once
  323. // IMPORTANT: each iteration needs to draw the same, to avoid strange effects
  324. // use a copy of values that might change, don't read e.g. from analog or pins in the loop!
  325. display.fillScreen(GxEPD_WHITE); // set the background to white (fill the buffer with value for white)
  326. display.setCursor(x, y); // set the postition to start printing text
  327. display.print(text); // print some text
  328. // end of part executed multiple times
  329. }
  330. // tell the graphics class to transfer the buffer content (page) to the controller buffer
  331. // the graphics class will command the controller to refresh to the screen when the last page has been transferred
  332. // returns true if more pages need be drawn and transferred
  333. // returns false if the last page has been transferred and the screen refreshed for panels without fast partial update
  334. // returns false for panels with fast partial update when the controller buffer has been written once more, to make the differential buffers equal
  335. // (for full buffered with fast partial update the (full) buffer is just transferred again, and false returned)
  336. while (display.nextPage());
  337. //Serial.println("helloWorld done");
  338. }
  339. void helloFullScreenPartialMode()
  340. {
  341. //Serial.println("helloFullScreenPartialMode");
  342. const char fullscreen[] = "full screen update";
  343. const char fpm[] = "fast partial mode";
  344. const char spm[] = "slow partial mode";
  345. const char npm[] = "no partial mode";
  346. display.setPartialWindow(0, 0, display.width(), display.height());
  347. display.setRotation(1);
  348. display.setFont(&FreeMonoBold9pt7b);
  349. display.setTextColor(GxEPD_BLACK);
  350. const char* updatemode;
  351. if (display.epd2.hasFastPartialUpdate)
  352. {
  353. updatemode = fpm;
  354. }
  355. else if (display.epd2.hasPartialUpdate)
  356. {
  357. updatemode = spm;
  358. }
  359. else
  360. {
  361. updatemode = npm;
  362. }
  363. // do this outside of the loop
  364. int16_t tbx, tby; uint16_t tbw, tbh;
  365. // center update text
  366. display.getTextBounds(fullscreen, 0, 0, &tbx, &tby, &tbw, &tbh);
  367. uint16_t utx = ((display.width() - tbw) / 2) - tbx;
  368. uint16_t uty = ((display.height() / 4) - tbh / 2) - tby;
  369. // center update mode
  370. display.getTextBounds(updatemode, 0, 0, &tbx, &tby, &tbw, &tbh);
  371. uint16_t umx = ((display.width() - tbw) / 2) - tbx;
  372. uint16_t umy = ((display.height() * 3 / 4) - tbh / 2) - tby;
  373. // center HelloWorld
  374. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  375. uint16_t hwx = ((display.width() - tbw) / 2) - tbx;
  376. uint16_t hwy = ((display.height() - tbh) / 2) - tby;
  377. display.firstPage();
  378. do
  379. {
  380. display.fillScreen(GxEPD_WHITE);
  381. display.setCursor(hwx, hwy);
  382. display.print(HelloWorld);
  383. display.setCursor(utx, uty);
  384. display.print(fullscreen);
  385. display.setCursor(umx, umy);
  386. display.print(updatemode);
  387. }
  388. while (display.nextPage());
  389. //Serial.println("helloFullScreenPartialMode done");
  390. }
  391. void helloArduino()
  392. {
  393. //Serial.println("helloArduino");
  394. display.setRotation(1);
  395. display.setFont(&FreeMonoBold9pt7b);
  396. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  397. int16_t tbx, tby; uint16_t tbw, tbh;
  398. // align with centered HelloWorld
  399. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  400. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  401. // height might be different
  402. display.getTextBounds(HelloArduino, 0, 0, &tbx, &tby, &tbw, &tbh);
  403. uint16_t y = ((display.height() / 4) - tbh / 2) - tby; // y is base line!
  404. // make the window big enough to cover (overwrite) descenders of previous text
  405. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  406. uint16_t wy = (display.height() / 4) - wh / 2;
  407. display.setPartialWindow(0, wy, display.width(), wh);
  408. display.firstPage();
  409. do
  410. {
  411. display.fillScreen(GxEPD_WHITE);
  412. //display.drawRect(x, y - tbh, tbw, tbh, GxEPD_BLACK);
  413. display.setCursor(x, y);
  414. display.print(HelloArduino);
  415. }
  416. while (display.nextPage());
  417. delay(1000);
  418. //Serial.println("helloArduino done");
  419. }
  420. void helloEpaper()
  421. {
  422. //Serial.println("helloEpaper");
  423. display.setRotation(1);
  424. display.setFont(&FreeMonoBold9pt7b);
  425. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  426. int16_t tbx, tby; uint16_t tbw, tbh;
  427. // align with centered HelloWorld
  428. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  429. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  430. // height might be different
  431. display.getTextBounds(HelloEpaper, 0, 0, &tbx, &tby, &tbw, &tbh);
  432. uint16_t y = (display.height() * 3 / 4) + tbh / 2; // y is base line!
  433. // make the window big enough to cover (overwrite) descenders of previous text
  434. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  435. uint16_t wy = (display.height() * 3 / 4) - wh / 2;
  436. display.setPartialWindow(0, wy, display.width(), wh);
  437. display.firstPage();
  438. do
  439. {
  440. display.fillScreen(GxEPD_WHITE);
  441. display.setCursor(x, y);
  442. display.print(HelloEpaper);
  443. }
  444. while (display.nextPage());
  445. //Serial.println("helloEpaper done");
  446. }
  447. #if defined(ESP8266) || defined(ESP32)
  448. #include <StreamString.h>
  449. #define PrintString StreamString
  450. #else
  451. class PrintString : public Print, public String
  452. {
  453. public:
  454. size_t write(uint8_t data) override
  455. {
  456. return concat(char(data));
  457. };
  458. };
  459. #endif
  460. void helloValue(double v, int digits)
  461. {
  462. //Serial.println("helloValue");
  463. display.setRotation(1);
  464. display.setFont(&FreeMonoBold9pt7b);
  465. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  466. PrintString valueString;
  467. valueString.print(v, digits);
  468. int16_t tbx, tby; uint16_t tbw, tbh;
  469. display.getTextBounds(valueString, 0, 0, &tbx, &tby, &tbw, &tbh);
  470. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  471. uint16_t y = (display.height() * 3 / 4) + tbh / 2; // y is base line!
  472. // show what happens, if we use the bounding box for partial window
  473. uint16_t wx = (display.width() - tbw) / 2;
  474. uint16_t wy = (display.height() * 3 / 4) - tbh / 2;
  475. display.setPartialWindow(wx, wy, tbw, tbh);
  476. display.firstPage();
  477. do
  478. {
  479. display.fillScreen(GxEPD_WHITE);
  480. display.setCursor(x, y);
  481. display.print(valueString);
  482. }
  483. while (display.nextPage());
  484. delay(2000);
  485. // make the partial window big enough to cover the previous text
  486. uint16_t ww = tbw; // remember window width
  487. display.getTextBounds(HelloEpaper, 0, 0, &tbx, &tby, &tbw, &tbh);
  488. // adjust, because HelloEpaper was aligned, not centered (could calculate this to be precise)
  489. ww = max(ww, uint16_t(tbw + 12)); // 12 seems ok
  490. wx = (display.width() - tbw) / 2;
  491. // make the window big enough to cover (overwrite) descenders of previous text
  492. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  493. wy = (display.height() * 3 / 4) - wh / 2;
  494. display.setPartialWindow(wx, wy, ww, wh);
  495. // alternately use the whole width for partial window
  496. //display.setPartialWindow(0, wy, display.width(), wh);
  497. display.firstPage();
  498. do
  499. {
  500. display.fillScreen(GxEPD_WHITE);
  501. display.setCursor(x, y);
  502. display.print(valueString);
  503. }
  504. while (display.nextPage());
  505. //Serial.println("helloValue done");
  506. }
  507. void deepSleepTest()
  508. {
  509. //Serial.println("deepSleepTest");
  510. const char hibernating[] = "hibernating ...";
  511. const char wokeup[] = "woke up";
  512. const char from[] = "from deep sleep";
  513. const char again[] = "again";
  514. display.setRotation(1);
  515. display.setFont(&FreeMonoBold9pt7b);
  516. display.setTextColor(GxEPD_BLACK);
  517. int16_t tbx, tby; uint16_t tbw, tbh;
  518. // center text
  519. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  520. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  521. uint16_t y = ((display.height() - tbh) / 2) - tby;
  522. display.setFullWindow();
  523. display.firstPage();
  524. do
  525. {
  526. display.fillScreen(GxEPD_WHITE);
  527. display.setCursor(x, y);
  528. display.print(hibernating);
  529. }
  530. while (display.nextPage());
  531. display.hibernate();
  532. delay(5000);
  533. display.getTextBounds(wokeup, 0, 0, &tbx, &tby, &tbw, &tbh);
  534. uint16_t wx = (display.width() - tbw) / 2;
  535. uint16_t wy = (display.height() / 3) + tbh / 2; // y is base line!
  536. display.getTextBounds(from, 0, 0, &tbx, &tby, &tbw, &tbh);
  537. uint16_t fx = (display.width() - tbw) / 2;
  538. uint16_t fy = (display.height() * 2 / 3) + tbh / 2; // y is base line!
  539. display.firstPage();
  540. do
  541. {
  542. display.fillScreen(GxEPD_WHITE);
  543. display.setCursor(wx, wy);
  544. display.print(wokeup);
  545. display.setCursor(fx, fy);
  546. display.print(from);
  547. }
  548. while (display.nextPage());
  549. delay(5000);
  550. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  551. uint16_t hx = (display.width() - tbw) / 2;
  552. uint16_t hy = (display.height() / 3) + tbh / 2; // y is base line!
  553. display.getTextBounds(again, 0, 0, &tbx, &tby, &tbw, &tbh);
  554. uint16_t ax = (display.width() - tbw) / 2;
  555. uint16_t ay = (display.height() * 2 / 3) + tbh / 2; // y is base line!
  556. display.firstPage();
  557. do
  558. {
  559. display.fillScreen(GxEPD_WHITE);
  560. display.setCursor(hx, hy);
  561. display.print(hibernating);
  562. display.setCursor(ax, ay);
  563. display.print(again);
  564. }
  565. while (display.nextPage());
  566. display.hibernate();
  567. //Serial.println("deepSleepTest done");
  568. }
  569. void showBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool partial)
  570. {
  571. //Serial.println("showBox");
  572. display.setRotation(1);
  573. if (partial)
  574. {
  575. display.setPartialWindow(x, y, w, h);
  576. }
  577. else
  578. {
  579. display.setFullWindow();
  580. }
  581. display.firstPage();
  582. do
  583. {
  584. display.fillScreen(GxEPD_WHITE);
  585. display.fillRect(x, y, w, h, GxEPD_BLACK);
  586. }
  587. while (display.nextPage());
  588. //Serial.println("showBox done");
  589. }
  590. void drawCornerTest()
  591. {
  592. display.setFullWindow();
  593. display.setFont(&FreeMonoBold9pt7b);
  594. display.setTextColor(GxEPD_BLACK);
  595. for (uint16_t r = 0; r <= 4; r++)
  596. {
  597. display.setRotation(r);
  598. display.firstPage();
  599. do
  600. {
  601. display.fillScreen(GxEPD_WHITE);
  602. display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
  603. display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
  604. display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
  605. display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
  606. display.setCursor(display.width() / 2, display.height() / 2);
  607. display.print(display.getRotation());
  608. }
  609. while (display.nextPage());
  610. delay(2000);
  611. }
  612. }
  613. void showFont(const char name[], const GFXfont* f)
  614. {
  615. display.setFullWindow();
  616. display.setRotation(0);
  617. display.setTextColor(GxEPD_BLACK);
  618. display.firstPage();
  619. do
  620. {
  621. drawFont(name, f);
  622. }
  623. while (display.nextPage());
  624. }
  625. void drawFont(const char name[], const GFXfont* f)
  626. {
  627. //display.setRotation(0);
  628. display.fillScreen(GxEPD_WHITE);
  629. display.setTextColor(GxEPD_BLACK);
  630. display.setFont(f);
  631. display.setCursor(0, 0);
  632. display.println();
  633. display.println(name);
  634. display.println(" !\"#$%&'()*+,-./");
  635. display.println("0123456789:;<=>?");
  636. display.println("@ABCDEFGHIJKLMNO");
  637. display.println("PQRSTUVWXYZ[\\]^_");
  638. if (display.epd2.hasColor)
  639. {
  640. display.setTextColor(GxEPD_RED);
  641. }
  642. display.println("`abcdefghijklmno");
  643. display.println("pqrstuvwxyz{|}~ ");
  644. }
  645. // note for partial update window and setPartialWindow() method:
  646. // partial update window size and position is on byte boundary in physical x direction
  647. // the size is increased in setPartialWindow() if x or w are not multiple of 8 for even rotation, y or h for odd rotation
  648. // see also comment in GxEPD2_BW.h, GxEPD2_3C.h or GxEPD2_GFX.h for method setPartialWindow()
  649. // showPartialUpdate() purposely uses values that are not multiples of 8 to test this
  650. void showPartialUpdate()
  651. {
  652. // some useful background
  653. helloWorld();
  654. // use asymmetric values for test
  655. uint16_t box_x = 10;
  656. uint16_t box_y = 15;
  657. uint16_t box_w = 70;
  658. uint16_t box_h = 20;
  659. uint16_t cursor_y = box_y + box_h - 6;
  660. float value = 13.95;
  661. uint16_t incr = display.epd2.hasFastPartialUpdate ? 1 : 3;
  662. display.setFont(&FreeMonoBold9pt7b);
  663. display.setTextColor(GxEPD_BLACK);
  664. // show where the update box is
  665. for (uint16_t r = 0; r < 4; r++)
  666. {
  667. display.setRotation(r);
  668. display.setPartialWindow(box_x, box_y, box_w, box_h);
  669. display.firstPage();
  670. do
  671. {
  672. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_BLACK);
  673. //display.fillScreen(GxEPD_BLACK);
  674. }
  675. while (display.nextPage());
  676. delay(2000);
  677. display.firstPage();
  678. do
  679. {
  680. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  681. }
  682. while (display.nextPage());
  683. delay(1000);
  684. }
  685. //return;
  686. // show updates in the update box
  687. for (uint16_t r = 0; r < 4; r++)
  688. {
  689. display.setRotation(r);
  690. display.setPartialWindow(box_x, box_y, box_w, box_h);
  691. for (uint16_t i = 1; i <= 10; i += incr)
  692. {
  693. display.firstPage();
  694. do
  695. {
  696. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  697. display.setCursor(box_x, cursor_y);
  698. display.print(value * i, 2);
  699. }
  700. while (display.nextPage());
  701. delay(500);
  702. }
  703. delay(1000);
  704. display.firstPage();
  705. do
  706. {
  707. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  708. }
  709. while (display.nextPage());
  710. delay(1000);
  711. }
  712. }
  713. void drawBitmaps()
  714. {
  715. display.setFullWindow();
  716. #ifdef _GxBitmaps104x212_H_
  717. drawBitmaps104x212();
  718. #endif
  719. #ifdef _GxBitmaps128x250_H_
  720. drawBitmaps128x250();
  721. #endif
  722. #ifdef _GxBitmaps128x296_H_
  723. drawBitmaps128x296();
  724. #endif
  725. #ifdef _GxBitmaps176x264_H_
  726. drawBitmaps176x264();
  727. #endif
  728. #ifdef _GxBitmaps400x300_H_
  729. drawBitmaps400x300();
  730. #endif
  731. #ifdef _GxBitmaps640x384_H_
  732. drawBitmaps640x384();
  733. #endif
  734. #ifdef _WS_Bitmaps800x600_H_
  735. drawBitmaps800x600();
  736. #endif
  737. // 3-color
  738. #ifdef _GxBitmaps3c104x212_H_
  739. drawBitmaps3c104x212();
  740. #endif
  741. #ifdef _GxBitmaps3c128x296_H_
  742. drawBitmaps3c128x296();
  743. #endif
  744. #ifdef _GxBitmaps3c176x264_H_
  745. drawBitmaps3c176x264();
  746. #endif
  747. #ifdef _GxBitmaps3c400x300_H_
  748. drawBitmaps3c400x300();
  749. #endif
  750. // show these after the specific bitmaps
  751. #ifdef _GxBitmaps200x200_H_
  752. drawBitmaps200x200();
  753. #endif
  754. // 3-color
  755. #ifdef _GxBitmaps3c200x200_H_
  756. drawBitmaps3c200x200();
  757. #endif
  758. }
  759. #ifdef _GxBitmaps200x200_H_
  760. void drawBitmaps200x200()
  761. {
  762. #if defined(__AVR)
  763. const unsigned char* bitmaps[] =
  764. {
  765. logo200x200, first200x200 //, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  766. };
  767. #elif defined(_BOARD_GENERIC_STM32F103C_H_)
  768. const unsigned char* bitmaps[] =
  769. {
  770. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200 //, sixth200x200, senventh200x200, eighth200x200
  771. };
  772. #else
  773. const unsigned char* bitmaps[] =
  774. {
  775. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  776. };
  777. #endif
  778. if (display.epd2.panel == GxEPD2::GDEP015OC1)
  779. {
  780. bool m = display.mirror(true);
  781. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  782. {
  783. display.firstPage();
  784. do
  785. {
  786. display.fillScreen(GxEPD_WHITE);
  787. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  788. }
  789. while (display.nextPage());
  790. delay(2000);
  791. }
  792. display.mirror(m);
  793. }
  794. //else
  795. {
  796. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  797. display.clearScreen(); // use default for white
  798. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  799. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  800. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  801. {
  802. display.drawImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  803. delay(2000);
  804. }
  805. }
  806. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  807. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  808. {
  809. int16_t x = -60;
  810. int16_t y = -60;
  811. for (uint16_t j = 0; j < 10; j++)
  812. {
  813. display.writeScreenBuffer(); // use default for white
  814. display.writeImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  815. display.refresh(true);
  816. if (display.epd2.hasFastPartialUpdate)
  817. {
  818. // for differential update: set previous buffer equal to current buffer in controller
  819. display.epd2.writeScreenBufferAgain(); // use default for white
  820. display.epd2.writeImageAgain(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  821. }
  822. delay(2000);
  823. x += 40;
  824. y += 40;
  825. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  826. }
  827. if (!display.epd2.hasFastPartialUpdate) break; // comment out for full show
  828. break; // comment out for full show
  829. }
  830. display.writeScreenBuffer(); // use default for white
  831. display.writeImage(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  832. display.writeImage(bitmaps[0], int16_t(int16_t(display.epd2.WIDTH) - 200), int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, mirror_y, true);
  833. display.refresh(true);
  834. delay(2000);
  835. }
  836. #endif
  837. #ifdef _GxBitmaps104x212_H_
  838. void drawBitmaps104x212()
  839. {
  840. #if !defined(__AVR)
  841. const unsigned char* bitmaps[] =
  842. {
  843. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  844. };
  845. #else
  846. const unsigned char* bitmaps[] =
  847. {
  848. WS_Bitmap104x212, Bitmap104x212_1, Bitmap104x212_2, Bitmap104x212_3
  849. };
  850. #endif
  851. if (display.epd2.panel == GxEPD2::GDEW0213I5F)
  852. {
  853. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  854. {
  855. display.firstPage();
  856. do
  857. {
  858. display.fillScreen(GxEPD_WHITE);
  859. display.drawBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  860. }
  861. while (display.nextPage());
  862. delay(2000);
  863. }
  864. }
  865. }
  866. #endif
  867. #ifdef _GxBitmaps128x250_H_
  868. void drawBitmaps128x250()
  869. {
  870. #if !defined(__AVR)
  871. const unsigned char* bitmaps[] =
  872. {
  873. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  874. };
  875. #else
  876. const unsigned char* bitmaps[] =
  877. {
  878. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  879. };
  880. #endif
  881. if ((display.epd2.panel == GxEPD2::GDE0213B1) || (display.epd2.panel == GxEPD2::GDEH0213B72))
  882. {
  883. bool m = display.mirror(true);
  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. display.mirror(m);
  896. }
  897. }
  898. #endif
  899. #ifdef _GxBitmaps128x296_H_
  900. void drawBitmaps128x296()
  901. {
  902. #if !defined(__AVR)
  903. const unsigned char* bitmaps[] =
  904. {
  905. Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
  906. };
  907. #else
  908. const unsigned char* bitmaps[] =
  909. {
  910. Bitmap128x296_1, logo128x296 //, first128x296, second128x296, third128x296
  911. };
  912. #endif
  913. if (display.epd2.panel == GxEPD2::GDEH029A1)
  914. {
  915. bool m = display.mirror(true);
  916. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  917. {
  918. display.firstPage();
  919. do
  920. {
  921. display.fillScreen(GxEPD_WHITE);
  922. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  923. }
  924. while (display.nextPage());
  925. delay(2000);
  926. }
  927. display.mirror(m);
  928. }
  929. }
  930. #endif
  931. #ifdef _GxBitmaps176x264_H_
  932. void drawBitmaps176x264()
  933. {
  934. #if !defined(__AVR)
  935. const unsigned char* bitmaps[] =
  936. {
  937. Bitmap176x264_1, Bitmap176x264_2, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  938. };
  939. #else
  940. const unsigned char* bitmaps[] =
  941. {
  942. Bitmap176x264_1, Bitmap176x264_2 //, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  943. };
  944. #endif
  945. if (display.epd2.panel == GxEPD2::GDEW027W3)
  946. {
  947. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  948. {
  949. display.firstPage();
  950. do
  951. {
  952. display.fillScreen(GxEPD_WHITE);
  953. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  954. }
  955. while (display.nextPage());
  956. delay(2000);
  957. }
  958. }
  959. }
  960. #endif
  961. #ifdef _GxBitmaps400x300_H_
  962. void drawBitmaps400x300()
  963. {
  964. #if !defined(__AVR)
  965. const unsigned char* bitmaps[] =
  966. {
  967. Bitmap400x300_1, Bitmap400x300_2
  968. };
  969. #else
  970. const unsigned char* bitmaps[] = {}; // not enough code space
  971. #endif
  972. if (display.epd2.panel == GxEPD2::GDEW042T2)
  973. {
  974. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  975. {
  976. display.firstPage();
  977. do
  978. {
  979. display.fillScreen(GxEPD_WHITE);
  980. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  981. }
  982. while (display.nextPage());
  983. delay(2000);
  984. }
  985. }
  986. }
  987. #endif
  988. #ifdef _GxBitmaps640x384_H_
  989. void drawBitmaps640x384()
  990. {
  991. #if !defined(__AVR)
  992. const unsigned char* bitmaps[] =
  993. {
  994. Bitmap640x384_1, Bitmap640x384_2
  995. };
  996. #else
  997. const unsigned char* bitmaps[] = {}; // not enough code space
  998. #endif
  999. if ((display.epd2.panel == GxEPD2::GDEW075T8) || (display.epd2.panel == GxEPD2::GDEW075Z09))
  1000. {
  1001. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  1002. {
  1003. display.firstPage();
  1004. do
  1005. {
  1006. display.fillScreen(GxEPD_WHITE);
  1007. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1008. }
  1009. while (display.nextPage());
  1010. delay(2000);
  1011. }
  1012. }
  1013. }
  1014. #endif
  1015. #ifdef _WS_Bitmaps800x600_H_
  1016. void drawBitmaps800x600()
  1017. {
  1018. #if defined(ESP8266) || defined(ESP32)
  1019. if (display.epd2.panel == GxEPD2::ED060SCT)
  1020. {
  1021. // Serial.print("sizeof(WS_zoo_800x600) is "); Serial.println(sizeof(WS_zoo_800x600));
  1022. display.drawNative(WS_zoo_800x600, 0, 0, 0, 800, 600, false, false, true);
  1023. delay(2000);
  1024. // Serial.print("sizeof(WS_pic_1200x825) is "); Serial.println(sizeof(WS_pic_1200x825));
  1025. // display.drawNative((const uint8_t*)WS_pic_1200x825, 0, 0, 0, 1200, 825, false, false, true);
  1026. // delay(2000);
  1027. // Serial.print("sizeof(WS_acaa_1024x731) is "); Serial.println(sizeof(WS_acaa_1024x731));
  1028. // display.drawNative(WS_acaa_1024x731, 0, 0, 0, 1024, 731, false, false, true);
  1029. // delay(2000);
  1030. }
  1031. #endif
  1032. }
  1033. #endif
  1034. struct bitmap_pair
  1035. {
  1036. const unsigned char* black;
  1037. const unsigned char* red;
  1038. };
  1039. #ifdef _GxBitmaps3c200x200_H_
  1040. void drawBitmaps3c200x200()
  1041. {
  1042. bitmap_pair bitmap_pairs[] =
  1043. {
  1044. //{Bitmap3c200x200_black, Bitmap3c200x200_red},
  1045. {WS_Bitmap3c200x200_black, WS_Bitmap3c200x200_red}
  1046. };
  1047. if (display.epd2.panel == GxEPD2::GDEW0154Z04)
  1048. {
  1049. display.firstPage();
  1050. do
  1051. {
  1052. display.fillScreen(GxEPD_WHITE);
  1053. // Bitmap3c200x200_black has 2 bits per pixel
  1054. // taken from Adafruit_GFX.cpp, modified
  1055. int16_t byteWidth = (display.epd2.WIDTH + 7) / 8; // Bitmap scanline pad = whole byte
  1056. uint8_t byte = 0;
  1057. for (int16_t j = 0; j < display.epd2.HEIGHT; j++)
  1058. {
  1059. for (int16_t i = 0; i < display.epd2.WIDTH; i++)
  1060. {
  1061. if (i & 3) byte <<= 2;
  1062. else
  1063. {
  1064. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  1065. byte = pgm_read_byte(&Bitmap3c200x200_black[j * byteWidth * 2 + i / 4]);
  1066. #else
  1067. byte = Bitmap3c200x200_black[j * byteWidth * 2 + i / 4];
  1068. #endif
  1069. }
  1070. if (!(byte & 0x80))
  1071. {
  1072. display.drawPixel(i, j, GxEPD_BLACK);
  1073. }
  1074. }
  1075. }
  1076. display.drawInvertedBitmap(0, 0, Bitmap3c200x200_red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1077. }
  1078. while (display.nextPage());
  1079. delay(2000);
  1080. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1081. {
  1082. display.firstPage();
  1083. do
  1084. {
  1085. display.fillScreen(GxEPD_WHITE);
  1086. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1087. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1088. }
  1089. while (display.nextPage());
  1090. delay(2000);
  1091. }
  1092. }
  1093. if (display.epd2.hasColor)
  1094. {
  1095. display.clearScreen(); // use default for white
  1096. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  1097. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  1098. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1099. {
  1100. display.drawImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  1101. delay(2000);
  1102. }
  1103. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1104. {
  1105. int16_t x = -60;
  1106. int16_t y = -60;
  1107. for (uint16_t j = 0; j < 10; j++)
  1108. {
  1109. display.writeScreenBuffer(); // use default for white
  1110. display.writeImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  1111. display.refresh();
  1112. delay(1000);
  1113. x += 40;
  1114. y += 40;
  1115. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  1116. }
  1117. }
  1118. display.writeScreenBuffer(); // use default for white
  1119. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, 0, 0, 200, 200, false, false, true);
  1120. 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);
  1121. display.refresh();
  1122. delay(2000);
  1123. }
  1124. }
  1125. #endif
  1126. #ifdef _GxBitmaps3c104x212_H_
  1127. void drawBitmaps3c104x212()
  1128. {
  1129. #if !defined(__AVR)
  1130. bitmap_pair bitmap_pairs[] =
  1131. {
  1132. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  1133. {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  1134. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  1135. };
  1136. #else
  1137. bitmap_pair bitmap_pairs[] =
  1138. {
  1139. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  1140. //{Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  1141. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  1142. };
  1143. #endif
  1144. if (display.epd2.panel == GxEPD2::GDEW0213Z16)
  1145. {
  1146. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1147. {
  1148. display.firstPage();
  1149. do
  1150. {
  1151. display.fillScreen(GxEPD_WHITE);
  1152. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1153. if (bitmap_pairs[i].red == WS_Bitmap3c104x212_red)
  1154. {
  1155. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1156. }
  1157. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1158. }
  1159. while (display.nextPage());
  1160. delay(2000);
  1161. }
  1162. }
  1163. }
  1164. #endif
  1165. #ifdef _GxBitmaps3c128x296_H_
  1166. void drawBitmaps3c128x296()
  1167. {
  1168. #if !defined(__AVR)
  1169. bitmap_pair bitmap_pairs[] =
  1170. {
  1171. {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1172. {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1173. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1174. };
  1175. #else
  1176. bitmap_pair bitmap_pairs[] =
  1177. {
  1178. //{Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1179. //{Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1180. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1181. };
  1182. #endif
  1183. if (display.epd2.panel == GxEPD2::GDEW029Z10)
  1184. {
  1185. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1186. {
  1187. display.firstPage();
  1188. do
  1189. {
  1190. display.fillScreen(GxEPD_WHITE);
  1191. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1192. if (bitmap_pairs[i].red == WS_Bitmap3c128x296_red)
  1193. {
  1194. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1195. }
  1196. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1197. }
  1198. while (display.nextPage());
  1199. delay(2000);
  1200. }
  1201. }
  1202. }
  1203. #endif
  1204. #ifdef _GxBitmaps3c176x264_H_
  1205. void drawBitmaps3c176x264()
  1206. {
  1207. bitmap_pair bitmap_pairs[] =
  1208. {
  1209. {Bitmap3c176x264_black, Bitmap3c176x264_red}
  1210. };
  1211. if (display.epd2.panel == GxEPD2::GDEW027C44)
  1212. {
  1213. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1214. {
  1215. display.firstPage();
  1216. do
  1217. {
  1218. display.fillScreen(GxEPD_WHITE);
  1219. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1220. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1221. }
  1222. while (display.nextPage());
  1223. delay(2000);
  1224. }
  1225. }
  1226. }
  1227. #endif
  1228. #ifdef _GxBitmaps3c400x300_H_
  1229. void drawBitmaps3c400x300()
  1230. {
  1231. #if !defined(__AVR)
  1232. bitmap_pair bitmap_pairs[] =
  1233. {
  1234. {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
  1235. {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
  1236. {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
  1237. };
  1238. #else
  1239. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1240. #endif
  1241. if (display.epd2.panel == GxEPD2::GDEW042Z15)
  1242. {
  1243. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1244. {
  1245. display.firstPage();
  1246. do
  1247. {
  1248. display.fillScreen(GxEPD_WHITE);
  1249. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1250. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1251. }
  1252. while (display.nextPage());
  1253. delay(2000);
  1254. }
  1255. }
  1256. }
  1257. #endif