print("Hello, ESP32!")
from machine import Pin, I2C # Import I2C from machine
from time import sleep
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
# Pin setup
pin_LED = Pin(0, Pin.OUT) # LED output pin
pin_PB = Pin(14, Pin.IN) # Button input pin with pull-up
slide_pin = Pin(27, Pin.IN, Pin.PULL_UP) # Slide switch input pin with pull-up
# I2C setup for LCD
I2C_ADDR = 0x27 # Default I2C address for 2004 LCD
i2c = I2C(0, sda=Pin(21), scl=Pin(22), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, 4, 20) # 4 rows and 20 columns
# Function to display a message based on the slide switch state
def display_message():
if slide_pin.value() == 0: # When the slide switch is ON (connected to GND)
lcd.clear()
lcd.putstr("HI")
else:
lcd.clear() # Clear the display when the slide switch is OFF
lcd.clear() # Clear LCD at the start
lcd.putstr("Hello")
sleep(2)
while True:
pin_LED.off()
val_PB = pin_PB.value()
print (val_PB)
if val_PB == 1:
pin_LED.on(),
sleep(0.1)