GxEPD2_HelloWorld.ino 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 constructor for your e-paper from GxEPD2_Example.ino, and for AVR needed #defines
  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. void setup()
  16. {
  17. display.init();
  18. helloWorld();
  19. display.hibernate();
  20. }
  21. const char HelloWorld[] = "Hello World!";
  22. void helloWorld()
  23. {
  24. display.setRotation(1);
  25. display.setFont(&FreeMonoBold9pt7b);
  26. display.setTextColor(GxEPD_BLACK);
  27. int16_t tbx, tby; uint16_t tbw, tbh;
  28. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  29. // center bounding box by transposition of origin:
  30. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  31. uint16_t y = ((display.height() - tbh) / 2) - tby;
  32. display.setFullWindow();
  33. display.firstPage();
  34. do
  35. {
  36. display.fillScreen(GxEPD_WHITE);
  37. display.setCursor(x, y);
  38. display.print(HelloWorld);
  39. }
  40. while (display.nextPage());
  41. }
  42. void loop() {};