GxEPD2_NotPagedExample.ino 45 KB

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