from machine import Pin, ADC, I2C
import time
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
# LCD setup
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400000)
lcd_address = i2c.scan()[0]
lcd = I2cLcd(i2c, lcd_address, 2, 16)
# LDR setup
ldr = ADC(Pin(26))
led = Pin(2, Pin.OUT)
flashlight_threshold = 60000
dark_threshold = 30000
while True:
light_value = ldr.read_u16()
print("Light Value:", light_value)
lcd.clear()
lcd.putstr("Light: {}\n".format(light_value))
if light_value > flashlight_threshold:
lcd.putstr("Flashlight ON")
led.off()
elif light_value < dark_threshold:
lcd.putstr("Status: Dark")
led.on()
else:
lcd.putstr("Status: Normal")
led.off()
time.sleep(1)