# Import Libraries
from machine import Pin, I2C
from time import sleep
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
# Configure GPIO pins
sda = Pin(0)
scl = Pin(1)
# Initialize I2C
i2c = I2C(0, sda=sda, scl=scl, freq=400000)
# Define I2C LCD parameters
I2C_ADDR = 39
I2C_ROWS = 2
I2C_COLS = 16
# Initialize the LCD
lcd = I2cLcd(i2c, I2C_ADDR, I2C_ROWS, I2C_COLS)
# GPIO configuration for the LDR
LDR_PIN = 16
ldr = Pin(LDR_PIN, Pin.IN)
def read_ldr():
return ldr.value()
while True:
light_intensity = read_ldr()
lcd.clear()
lcd.putstr("Light Intensity:")
lcd.move_to(0, 1)
if light_intensity == 1:
lcd.putstr(" DARK ")
else:
lcd.putstr(" LIGHT ")
sleep(1)