GxEPD2_Example.ino 41 KB

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