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)
BETA=3950
red=Pin(27,Pin.OUT)
green=Pin(22,Pin.OUT)
yellow=Pin(26,Pin.OUT)
while True:
temp=adc.read_u16()
celsius = 1 / (math.log(1 / (65535. / temp - 1)) / BETA + 1.0 / 298.15) - 273.15;
print(celsius)
lcd.clear()
lcd.putstr(str(celsius)+" *C")
if(celsius<0):
yellow.on()
green.off()
red.off()
elif(celsius>23):
yellow.off()
green.off()
red.on()
else:
yellow.off()
green.on()
red.off()
time.sleep(5)
yellow.off()
green.off()
red.off()
lcd.clear()
time.sleep(1)