from machine import ADC,Pin,I2C,Timer
import time
from math import log
from pico_i2c_lcd import I2cLcd
green=Pin(2,Pin.OUT)
yellow=Pin(3,Pin.OUT)
red=Pin(10,Pin.OUT)
sda=Pin(0)
scl = Pin(1)
i2c = I2C(0, sda=sda , scl=scl ,freq = 400000)
devices = i2c.scan()
if len(devices)<=0:
print("No devices found!")
else :
print(hex(devices[0]))
i2c_addr = devices[0]
lcd=I2cLcd(i2c,i2c_addr,2,16)
adc=ADC(0)
BETA=3950
cnt=0
def fn(timer):
global cnt
lcd.clear()
raw=adc.read_u16()
temp = 1 / (log(1 / (65535 / raw - 1)) / BETA + 1 / 298.15) - 273.15
green.value(0)
yellow.value(0)
red.value(0)
if temp >=10 and temp<=33 :
green.value(1)
cnt=0
elif cnt<=5:
yellow.value(1)
cnt=cnt+1
else :
red.value(1)
lcd.putstr("!!Danger!!")
t = Timer(period=1000,mode=Timer.PERIODIC,callback=fn)