from machine import I2C, ADC, Pin
from time import sleep
from pico_i2c_lcd import I2cLcd
# Untuk Photoresistor
ldr = ADC(Pin(26))
# Untuk LCD
i2c = I2C(0, sda=Pin(8), scl=Pin(9), freq=400000)
I2C_ADDR = i2c.scan()[0]
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
GAMMA = 0.7;
RL10 = 50;
while True:
light_value = ldr.read_u16()
voltage = light_value / 65535. * 5;
resistance = 2000 * voltage / (1 - voltage / 5);
lux_value = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
print(f"Light Value: {light_value}")
print(f"Lux Value: {lux_value}")
lcd.clear()
lcd.move_to(0, 0)
lcd.putstr(f"Light: {light_value:9}")
lcd.move_to(0, 1)
lcd.putstr(f"Lux: {lux_value:11f}")
sleep(2)