# Made by EasyCore github(https://github.com/exsycore)
# Thank link(https://randomnerdtutorials.com/micropython-i2c-lcd-esp32-esp8266/)
# for library i2c lcd
# sorry my english a little bit
# im student at TATC (computer technical 67219090038)
# Library
from time import sleep_ms
from machine import I2C, Pin
from machine_i2c_lcd import I2cLcd
# Wait for ready
sleep_ms(1000) # 1000 = 1 second
def Setup():
# Setup more pins
# (global) you can use this variable out of function
global Button
global LedRed
global lcd
Button = Pin(0, Pin.IN, Pin.PULL_UP)
LedRed = Pin(13, Pin.OUT)
# Setting Variable for LedRed to 0
LedRed.value(0)
# Pointer scan for i2c lcd
i2c = I2C(0, scl = Pin(22), sda = Pin(21), freq = 400000)
lcd_addr = i2c.scan()[0]
print(f"LCD Pointer: {hex(lcd_addr)}")
# Setup LCD
lcd = I2cLcd(i2c, lcd_addr, 2, 16) # 2 = Rows, 16 = Char lenght !!(Setup your LCD)
Setup()
# Function to checking the button
def IsOnButton() -> bool:
return not Button.value()
# make variable name led_state for checking
led_state = None
# make static string for lcd
lcd.clear() # clear string or text in lcd
lcd.putstr("LED: ") # put string to lcd for output
lcd.move_to(0, 1) # move_to is set cursor
lcd.putstr("Press Button")
# while loop is running always
# if you give "break" in this while loop
# then end while loop now
while True:
if IsOnButton():
if led_state != True:
LedRed.on()
lcd.move_to(5, 0)
lcd.putstr("ON ")
led_state = True
else:
if led_state != False:
LedRed.off()
lcd.move_to(5, 0)
lcd.putstr("OFF")
led_state = False