GxEPD2_HelloWorld.ino 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // GxEPD2_HelloWorld.ino by Jean-Marc Zingg
  2. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  3. //#include <GFX.h>
  4. #define ENABLE_GxEPD2_GFX 0
  5. #include <GxEPD2_BW.h> // including both doesn't hurt
  6. #include <GxEPD2_3C.h> // including both doesn't hurt
  7. #include <Fonts/FreeMonoBold9pt7b.h>
  8. // copy the constructor for your e-paper from GxEPD2_Example.ino (and for AVR boards needed #defines for MAX_HEIGHT).
  9. #define MAX_DISPLAY_BUFFER_SIZE 800 //
  10. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  11. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7)); // GDEP015OC1 no longer available
  12. //GxEPD2_BW<GxEPD2_154_D67, MAX_HEIGHT(GxEPD2_154_D67)> display(GxEPD2_154_D67(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7)); // GDEH0154D67
  13. // e.g. for Wemos D1 mini:
  14. //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
  15. // alternately you can copy the constructor from GxEPD2_constructor_examples.h or GxEPD2_boards_added.h
  16. // or you can uncomment the constructor line in one of these included headers
  17. #include "GxEPD2_constructor_examples.h"
  18. #include "GxEPD2_boards_added.h"
  19. // see GxEPD2_wiring_examples.h for wiring suggestions, the wiring corresponding to the constructor examples.
  20. // if you use a different wiring, you need to adapt the constructor parameters!
  21. void setup()
  22. {
  23. display.init();
  24. helloWorld();
  25. display.hibernate();
  26. }
  27. const char HelloWorld[] = "Hello World!";
  28. void helloWorld()
  29. {
  30. display.setRotation(1);
  31. display.setFont(&FreeMonoBold9pt7b);
  32. display.setTextColor(GxEPD_BLACK);
  33. int16_t tbx, tby; uint16_t tbw, tbh;
  34. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  35. // center the bounding box by transposition of the origin:
  36. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  37. uint16_t y = ((display.height() - tbh) / 2) - tby;
  38. display.setFullWindow();
  39. display.firstPage();
  40. do
  41. {
  42. display.fillScreen(GxEPD_WHITE);
  43. display.setCursor(x, y);
  44. display.print(HelloWorld);
  45. }
  46. while (display.nextPage());
  47. }
  48. void loop() {};