GxEPD2_Example.ino 52 KB

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