GxEPD2_HelloWorld.ino 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // GxEPD2_HelloWorld.ino by Jean-Marc Zingg
  2. // see GxEPD2_wiring_examples.h for wiring suggestions and examples
  3. // if you use a different wiring, you need to adapt the constructor parameters!
  4. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  5. //#include <GFX.h>
  6. #include <GxEPD2_BW.h>
  7. #include <GxEPD2_3C.h>
  8. #include <Fonts/FreeMonoBold9pt7b.h>
  9. // select the display class and display driver class in the following file (new style):
  10. #include "GxEPD2_display_selection_new_style.h"
  11. // or select the display constructor line in one of the following files (old style):
  12. #include "GxEPD2_display_selection.h"
  13. #include "GxEPD2_display_selection_added.h"
  14. // alternately you can copy the constructor from GxEPD2_display_selection.h or GxEPD2_display_selection_added.h to here
  15. // e.g. for Wemos D1 mini:
  16. //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
  17. void setup()
  18. {
  19. display.init();
  20. helloWorld();
  21. display.hibernate();
  22. }
  23. const char HelloWorld[] = "Hello World!";
  24. void helloWorld()
  25. {
  26. display.setRotation(1);
  27. display.setFont(&FreeMonoBold9pt7b);
  28. display.setTextColor(GxEPD_BLACK);
  29. int16_t tbx, tby; uint16_t tbw, tbh;
  30. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  31. // center the bounding box by transposition of the origin:
  32. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  33. uint16_t y = ((display.height() - tbh) / 2) - tby;
  34. display.setFullWindow();
  35. display.firstPage();
  36. do
  37. {
  38. display.fillScreen(GxEPD_WHITE);
  39. display.setCursor(x, y);
  40. display.print(HelloWorld);
  41. }
  42. while (display.nextPage());
  43. }
  44. void loop() {};