import time
from machine import I2C, SoftI2C,Pin,ADC
from pico_i2c_lcd import I2cLcd
import math
yellow=Pin(0,Pin.OUT)
green=Pin(1,Pin.OUT)
red=Pin(2,Pin.OUT)
i2c=SoftI2C(sda=Pin(26),scl=Pin(27),freq=400000)
i2c_address=i2c.scan()[0]
lcd=I2cLcd(i2c,i2c_address,2,16)
adc=ADC(28)
#print("Hello, Pi Pico!")
while True:
temp=adc.read_u16()
lcd.clear()
lcd.move_to(1,0)
lcd.putstr(f"Analog:{temp}")
BETA=3950
celsius=1/(math.log(1/(65535/temp-1))/BETA+1.0/298.15)-273.15
lcd.move_to(1,1)
lcd.putstr(f"Digital:%.2f"%celsius)
time.sleep(1)
if celsius<0:
yellow.toggle()
time.sleep(1)
yellow.toggle()
elif celsius>=0 and celsius<23:
green.toggle()
time.sleep(1)
green.toggle()
else:
red.toggle()
time.sleep(1)
red.toggle()
#celsius>23 red