# MicroPython + ESP 32 + I2C-LCD-2x16-Modul Teil 2
import machine, time
from machine import Pin, SoftI2C
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
def uhrzeit():
while True:
print("Uhrzeit")
uhrzeit = "| {0:02d}:{1:02d}:{2:02d} |".format(time.localtime()[3],time.localtime()[4],time.localtime()[5])
print(uhrzeit)
I2C_ADDR = 0x27
totalRows = 2 # zwei Zeilen
totalColumns = 16 # 16 Zeichen je Zeile
SDA_Pin = 21 # D21 - gelb - SDA
SCL_Pin = 22 # D22 - orange - SCL
select = Pin(15)
right = Pin( 2)
down = Pin( 4)
i2c = SoftI2C(scl=Pin(SCL_Pin), sda=Pin(SDA_Pin), freq=10000)
lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColumns)
lcd.display_on()
lcd.backlight_on()
lcd.putstr("Hauptmenue")
wahl = 0
i=0
imax=3
while True:
print(select.value())
if wahl==0:
lcd.move_to(0,1) # Zeichen 0, Zeile 2
lcd.putstr(" ")
lcd.move_to(0,1) # Zeichen 0, Zeile 2
if i==0:
lcd.putstr("1 Uhrzeit")
else:
if i==1:
lcd.putstr("2 Stoppuhr")
else:
lcd.putstr("3 Counter")
time.sleep(0.25)
if select.value()==0:
if i==0:
uhrzeit()
elif i==1:
stoppuhr()
else:
counter()
i=i+1
# Anzeige wiederholen
if i==imax:
i=0