/*
Forum: https://forum.arduino.cc/t/buchstabenkonturen-von-text-nachlaufen-lassen/1416072/13
Wokwi: https://wokwi.com/projects/448534210941156353
Beispiel für das stückweise Aufbauen eines Textes von links nach rechts durch Verdeckung mit einem
Rechteck
Kein Glanzstück, aber es funktioniert als visuelles Beispiel
2025/11/24
ec2021
*/
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
const char txt[][22] = {"Stueckweiser Aufbau", "durchgefuehrt ", "per Verdeckung ", "mit einem Rechteck"};
constexpr byte textAnzahl = sizeof(txt) / sizeof(txt[0]);
constexpr byte xPos {0};
constexpr byte yPos {10};
constexpr byte fontHeight {12};
int schritt = 0;
int no = 0;
boolean nextText = false;
void setup() {
u8g.setFont(u8g_font_tpssb);
}
void loop() {
u8g.firstPage();
do {
if (textAufdecken(no, schritt)){
nextText = true;
};
} while ( u8g.nextPage() );
if (nextText){
no = (no+1) % textAnzahl;
nextText = false;
}
schritt++;
}
boolean textAufdecken(byte Number, int &wo) {
int laenge = (strlen(txt[Number]) - 1) * 7;
if (wo >= laenge) {
wo = 0;
return true;
}
u8g.setColorIndex(1);
for (byte i=0;i<=Number;i++){
u8g.drawStr(xPos, yPos+i*fontHeight*1.5, txt[i]);
}
u8g.setColorIndex(0);
u8g.drawBox(xPos + wo, yPos + Number*fontHeight*1.5 - fontHeight, laenge - wo, fontHeight * 1.5);
return false;
}