GxEPD2_NotPagedExample.ino 44 KB

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