import time
import machine
import math
from machine import I2C, SoftI2C, Pin, ADC
from pico_i2c_lcd import I2cLcd
led=Pin(20, Pin.OUT)
i2c = SoftI2C(sda=Pin(4), scl=Pin(7), freq=400000)
lcd_addr=i2c.scan()[0]
lcd=I2cLcd(i2c, lcd_addr, 2, 16)
lcd.move_to(0, 0)
adc1=ADC(26)
adc2=ADC(27)
while(1):
temp=adc1.read_u16()
l=adc2.read_u16()
BETA = 3950;
cel = 1 / (math.log(1 / (65535. / temp - 1)) / BETA + 1.0 / 298.15) - 273.15;
lcd.putstr(str(cel))
time.sleep(2)
lcd.clear()
GAMMA = 0.7;
RL10 = 50;
voltage = l / 65535. * 5;
resistance = 2000 * voltage / (1 - voltage / 5);
lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
lcd.putstr(str(lux))
time.sleep(2)
lcd.clear()
if(lux>3000):
lcd.clear()
lcd.putstr("Sunny")
led.on()
time.sleep(2)
lcd.clear()
led.off()