GxEPD2_Example.ino 52 KB

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