Skip to content

Instantly share code, notes, and snippets.

@tolik518
Last active December 12, 2023 12:38
Show Gist options
  • Save tolik518/8fb5edebb5a7771708c5fb22ee43d075 to your computer and use it in GitHub Desktop.
Save tolik518/8fb5edebb5a7771708c5fb22ee43d075 to your computer and use it in GitHub Desktop.
// 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 <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <Fonts/FreeMonoBold9pt7b.h>
// RP2040 SS =10, SCL(SCK) =13, SDA(MOSI) =11 ,BUSY = 7, RST = 9, DC = 8 W
GxEPD2_3C<GxEPD2_290_C90c, GxEPD2_290_C90c::HEIGHT> display(GxEPD2_290_C90c(/*CS*/ 10, /*DC=*/8, /*RST=*/9, /*BUSY=*/7)); // GDEM029C90 128x296, SSD1680
void setup() {
display.init(115200, true, 50, false);
delay(500);
}
const char HelloWorld[] = "Hallo wie gehts";
// Funktion, um Text auf dem Display anzuzeigen
void displayText(const char* text, int16_t x, int16_t y, uint16_t color) {
display.setTextColor(color);
int16_t tbx, tby;
uint16_t tbw, tbh;
display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh);
display.setCursor(((display.width() - tbw) / 2) - tbx, y);
display.print(text);
}
// Funktion, um einen Rahmen am Rand des Bildschirms anzuzeigen
void drawBorder() {
display.drawRect(0, 0, display.width(), display.height(), GxEPD_RED);
}
void loop() {
static uint16_t i = 0; // Statische Variable, um den Zählerstand zu halten
char buffer[30]; // Buffer für den zusammengesetzten Text
// Zusammensetzen des Textes und der Zählvariablen
snprintf(buffer, sizeof(buffer), "Counter: %d", i);
display.setRotation(1);
display.setFont(&FreeMonoBold9pt7b);
display.setFullWindow();
display.firstPage();
Serial.print("Counter value: ");
Serial.println(i);
Serial.print("Buffer content: ");
Serial.println(buffer);
do {
display.fillScreen(GxEPD_WHITE);
drawBorder();
displayText(HelloWorld, 0, ((display.height() / 2) - 9), GxEPD_BLACK);
displayText(buffer, 0, ((display.height() / 2) + 9), GxEPD_RED);
} while (display.nextPage());
delay(1000);
i++; // Zähler erhöhen
if (i > 1000) {
display.hibernate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment