import time,math
from machine import ADC,Pin,SoftI2C
from pico_i2c_lcd import I2cLcd
i2c = SoftI2C(sda=Pin(20),scl=Pin(1),freq=400000)
lcd_address = i2c.scan()[0]
print(lcd_address)
lcd = I2cLcd(i2c, lcd_address, 2, 16)
adc= ADC(28)
adcp=ADC(27)
BETA=3950
GAMMA = 0.7
RL10 = 50
while True:
temp=adc.read_u16()
photo_reading=adcp.read_u16()
voltage = photo_reading / 65535. * 5;
resistance = 2000 * voltage / (1-voltage / 5);
lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA))
celsius = 1 / (math.log(1 / (65535. / temp - 1)) / BETA + 1.0 / 298.15) - 273.15
print("lux: "+str(lux))
print("temp: "+str(celsius))
lcd.clear()
if(lux<=50 and celsius<=25):
lcd.putstr("Comfortable")
elif(lux>50 and celsius<=25):
lcd.putstr("High Light")
elif(celsius>25 and lux<=50):
lcd.putstr("High Temperature")
else:
lcd.putstr("Not Comfortable")
time.sleep(5)
lcd.clear()
time.sleep(5)