import time
from machine import Pin, ADC, I2C, SoftI2C,
from pico_i2c_lcd import I2cLcd
import math
i2c = SoftI2C(sda=Pin(20),scl=Pin(19),freq=400000)
led = Pin(5, Pin.OUT)
lcd_addr = i2c.scan()[0]
lcd = I2cLcd(i2c,lcd_addr, 2, 16)
lcd.clear()
lcd.move_to(5,1)
beta = 3950
adc = ADC(28)
while True:
led.off()
lcd.clear()
lcd.move_to(5,1)
tmp = adc.read_u16()
celsius = 1 / (math.log(1 / (65536 / tmp - 1)) / beta + 1.0 / 298.15) - 273.15;
celsius = round(celsius,2)
print(celsius)
if celsius > 40:
led.on()
lcd.putstr("{0} C".format(celsius))
time.sleep(1)