// ---------------------------------------------------------
// I2C - LCD Anzeige
// Pinning: ESP32 D22 <=> SCL I2C_LCD
// D21 <=> SDA
// 3V3 <=> Vcc
// GND <=> GND
// Befehle:
// oLCD.init ()
// oLCD.backlight ();
// oLCD.clear ();
// oLCD.setCursor (iSpalte,iZeile);
// oLCD.print ("Hallo");
#include <LiquidCrystal_I2C.h>
#include <string.h>
#include <stdio.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
const int ibutton = 9; // unten
const int ibutton2 = 3; // links
const int ibutton3 = 6; // rechts
const int ibutton4 = 5; // oben
int iSpalte = 0;
int iZeile = 0;
LiquidCrystal_I2C oLCD (I2C_ADDR, LCD_COLUMNS, LCD_LINES);
// ---------------------------------------------------------
char sLCDText[30];
void LCDPrintCharSZ (int iSpalte, int iZeile, char cZeichen)
{
char sBuchstabe[2];
if (iZeile < 0) return;
if (iSpalte < 0) return;
if (iZeile >= LCD_LINES) return;
if (iSpalte >= LCD_COLUMNS) return;
sprintf (sBuchstabe, "%c", cZeichen);
//sBuchstabe[0] = cZeichen;
//sBuchstabe[1] = '\0'
oLCD.setCursor (iSpalte, iZeile);
oLCD.print (sBuchstabe);
}
void LCDPrintSZ (int iSpalte, int iZeile)
{
int iIndex;
for(iIndex=0; iIndex < strlen (sLCDText); iIndex++)
{
LCDPrintCharSZ (iSpalte+iIndex, iZeile, sLCDText[iIndex]);
}
}
void setup()
{
oLCD.init();
oLCD.backlight();
strcpy (sLCDText, "12345678910");
LCDPrintSZ(0, 0);
}
void loop()
{
if (digitalRead(ibutton2) == LOW)
{
oLCD.init();
oLCD.backlight();
iZeile = iZeile - 1;
}
else if (digitalRead(ibutton3) == LOW)
{
iZeile = iZeile + 1;
}
// Verschieben des Textes um eine Spalte nach links
for (int i = 0; i < strlen(sLCDText); i++)
{
// Wenn der Text das Ende des Displays erreicht hat, beginnen Sie von vorne
if (iSpalte + i >= LCD_COLUMNS)
{
iSpalte = -i;
}
LCDPrintCharSZ(iSpalte + i, iZeile, sLCDText[i]);
}
iSpalte++; // Inkrementieren der Spaltenposition für den nächsten Durchlauf
delay(500); // Verzögerung für die Anzeige
}