// ---------------------------------------------------------
// 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>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
#define RAUF 4
#define RUNTER 2
#define RECHTS 5
#define LINKS 3
LiquidCrystal_I2C oLCD (I2C_ADDR, LCD_COLUMNS, LCD_LINES);
// ---------------------------------------------------------
#include <string.h>
#include <stdio.h>
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);
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 Button_press (int iSpalte, int iZeile)
{
int iButton_right;
int iButton_left;
int iButton_down;
int iButton_up;
for (;;)
{
iButton_right = digitalRead(RECHTS);
iButton_left = digitalRead(LINKS);
iButton_down = digitalRead(RUNTER);
iButton_up = digitalRead(RAUF);
if (iButton_right == 1)
{
iSpalte++;
}
if (iButton_left == 1)
{
iSpalte--;
}
if (iButton_down == 1)
{
iZeile++;
}
if (iButton_up == 1)
{
iZeile--;
}
LCDPrintSZ(iSpalte, iZeile);
delay(200);
oLCD.clear();
}
}
void setup()
{
oLCD.init();
oLCD.backlight();
strcpy (sLCDText,"1234567890");
Button_press (15,0);
}
void loop()
{
}