###########################
### Code in MicroPython ###
###########################

from machine import Pin, I2C	# For hardware functions
from i2c_lcd import I2cLcd		# For I²C LCD functions
import time						# For time functions

i2c = I2C(1, sda=Pin(6), scl=Pin(7), freq=400000)	# Initialize I2C for SEEED XIAO RP2040 (SDA=6, SCL=7)
I2C_ADDR = 0x27										# I²C LCD address found from scan
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)					# Function to name and give the parameters of the I²C LCD screen

lcd.move_to(0, 0)			# First line of the I²C LCD screen
lcd.putstr("LED STATUS")	# Message to display to the I²C LCD screen

led = Pin(2, Pin.OUT)	# Configure pin 2 as an output
button = Pin(4, Pin.IN)	# Configure pin 4 as an input

while True:								# Infinite loop
    buttonValue = button.value()		# Reading of the value of the button
    if buttonValue == 1:				# If the button is ON
        led.value(1)					# The led turns ON
        lcd.move_to(1, 0)				# Second line of the I²C LCD screen
        lcd.putstr("              ON")	# Message to display to the I²C LCD screen
    else:								# If the button is OFF ('0')
        led.value(0)					# The led turns OFF
        lcd.move_to(1, 0)				# Second line of the I²C LCD screen
        lcd.putstr("             OFF")	# Message to display to the I²C LCD screen