import time
import math
from machine import ADC, Pin,Timer,I2C,SoftI2C
from pico_i2c_lcd import I2cLcd
i2c=SoftI2C(sda=Pin(20),scl=Pin(19),freq=400000)
lcd_addr=i2c.scan()[0]
print(lcd_addr)
lcd=I2cLcd(i2c,lcd_addr,2,16)
led=Pin(17,Pin.OUT)
adc=ADC(26)
adc2=ADC(28)
while True:
l=adc2.read_u16()
temp=adc.read_u16()
b=3950
celcius=1/(math.log(1/(65535. / temp-1))/b+1.0/298.15)-273.15
lcd.putstr("T="+str(celcius)[:5])
if celcius>40:
led.on()
time.sleep(1)
led.off()
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))
print(temp)
print(lux)
print(" ")
lcd.move_to(8,0)
lcd.putstr("L="+str(lux)[:5])
if celcius<25 and lux<50:
lcd.move_to(1,1)
lcd.putstr("Dark and Cold")
if celcius>45 and lux>300:
lcd.move_to(1,1)
lcd.putstr("Bright and Hot")
else:
lcd.move_to(1,1)
lcd.putstr("Normal")
time.sleep(1)
lcd.clear()