GxEPD2_HelloWorld.ino 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <GxEPD2_7C.h>
  9. #include <Fonts/FreeMonoBold9pt7b.h>
  10. // select the display class and display driver class in the following file (new style):
  11. #include "GxEPD2_display_selection_new_style.h"
  12. // or select the display constructor line in one of the following files (old style):
  13. #include "GxEPD2_display_selection.h"
  14. #include "GxEPD2_display_selection_added.h"
  15. // alternately you can copy the constructor from GxEPD2_display_selection.h or GxEPD2_display_selection_added.h to here
  16. // e.g. for Wemos D1 mini:
  17. //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
  18. void setup()
  19. {
  20. //display.init(115200); // default 10ms reset pulse, e.g. for bare panels with DESPI-C02
  21. display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse
  22. helloWorld();
  23. display.hibernate();
  24. }
  25. const char HelloWorld[] = "Hello World!";
  26. void helloWorld()
  27. {
  28. display.setRotation(1);
  29. display.setFont(&FreeMonoBold9pt7b);
  30. display.setTextColor(GxEPD_BLACK);
  31. int16_t tbx, tby; uint16_t tbw, tbh;
  32. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  33. // center the bounding box by transposition of the origin:
  34. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  35. uint16_t y = ((display.height() - tbh) / 2) - tby;
  36. display.setFullWindow();
  37. display.firstPage();
  38. do
  39. {
  40. display.fillScreen(GxEPD_WHITE);
  41. display.setCursor(x, y);
  42. display.print(HelloWorld);
  43. }
  44. while (display.nextPage());
  45. }
  46. void loop() {};