So Iāve been playing around with this library for a couple of days now, and am sufficiently stumped as to how to get it to do what I want.
Goals:
- Display Full screen Images
- Display different sized text in the same update
- Show some text inverted in a configurable sized section with ānormalā text
- Completely clear the display
- Full buffer drawing
This is what I have now, using the 2.9" Waveshare display. Any help would be greatly appreciated.
#include <Adafruit_GFX_RK.h>
#include <GxEPD2_PP.h>
// base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
// enable or disable GxEPD2_GFX base class
#define ENABLE_GxEPD2_GFX 0
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <FreeMonoBold9pt7b.h>
#include <FreeMono12pt7b.h>
// #include "imagedata.h"
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=A2*/ SS, /*DC=*/ A1, /*RST=*/ A0, /*BUSY=*/ A4));
// GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=A2*/ SS, /*DC=*/ A1, /*RST=*/ A0, /*BUSY=*/ A4)); // GDEW029T5
#include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
const char HelloWorld[] = "Hello World!";
const char HelloArduino[] = "Hello Arduino!";
const char HelloEpaper[] = "Hello E-Paper!";
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("setup");
delay(100);
display.init(115200);
display.clearScreen();
display.writeScreenBuffer();
delay(1000);
drawBitmaps128x296();
drawBitmaps128x296();
display.clearScreen();
display.writeScreenBuffer();
delay(1000);
}
void loop()
{
//Serial.println("helloArduino");
display.setRotation(1);
display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
int16_t tbx, tby; uint16_t tbw, tbh;
// align with centered HelloWorld
display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
uint16_t x = ((display.width() - tbw) / 2) - tbx;
// height might be different
display.getTextBounds(HelloArduino, 0, 0, &tbx, &tby, &tbw, &tbh);
uint16_t y = ((display.height() / 4) - tbh / 2) - tby; // y is base line!
// make the window big enough to cover (overwrite) descenders of previous text
uint16_t wh = FreeMonoBold9pt7b.yAdvance;
uint16_t wy = (display.height() / 4) - wh / 2;
display.setFullWindow();
// display.setPartialWindow(8, wy, display.width(), wh);
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
//display.drawRect(x, y - tbh, tbw, tbh, GxEPD_BLACK);
display.setCursor(x, y);
display.print(HelloArduino);
display.setCursor(x - 40 , y + 80);
display.print(HelloEpaper);
display.setFont(&FreeMono12pt7b);
display.setCursor(x + 40 , y + 60);
display.print(HelloWorld);
}
while (display.nextPage());
delay(5000);
display.setFullWindow();
display.fillScreen(GxEPD_WHITE);
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
//display.drawRect(x, y - tbh, tbw, tbh, GxEPD_BLACK);
display.setCursor(x, y + 20);
display.print(HelloWorld);
}
while (display.nextPage());
delay(5000);
}
void drawBitmaps128x296()
{
const unsigned char* bitmaps[] =
{
Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
};
bool m = display.mirror(true);
for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
{
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
}
while (display.nextPage());
delay(2000);
}
display.mirror(m);
}