import time
import math
from machine import ADC,Pin,I2C,SoftI2C,RTC
from pico_i2c_lcd import I2cLcd
from lcd_api import LcdApi
adc= ADC(28)
i2c = (SoftI2C(sda=Pin(0),scl =Pin(1),freq=400000))
lcd_address = i2c.scan()[0]
lcd = I2cLcd(i2c,lcd_address,2,16)
red_led=Pin(4,Pin.OUT)
yellow_led=Pin(6,Pin.OUT)
green_led=Pin(10,Pin.OUT)
adc = ADC(28)
while True:
temp = adc.read_u16()
celsius = 1 / (math.log(1 / (65535. / temp - 1),10) / 3950 + 1.0 / 298.15) - 273.15;
print(celsius)
if celsius > 23:
red_led.on()
yellow_led.off()
green_led.off()
elif celsius < 0:
red_led.off()
yellow_led.on()
green_led.off()
else:
red_led.off()
yellow_led.off()
green_led.on()
time.sleep(1)
lcd.clear()
lcd.move_to(0, 0)
lcd.putstr("Temp: {:.2f} C".format(celsius))
print("Hello, Pi Pico!")