from machine import ADC,I2C,Pin,Timer
from pico_i2c_lcd import I2cLcd
import utime,math
sda=Pin(0)
scl=Pin(1)
i2c=I2C(0,sda=sda,scl=scl,freq=400000)
device=i2c.scan()
i2caddr=device[0]
lcd=I2cLcd(i2c,i2caddr,2,16)
A0=ADC(Pin(26))
while True:
lcd.clear()
val=A0.read_u16()
angle=(val/65535)*90
lcd.putstr(str(angle))
utime.sleep(1)
# led_g=Pin(3,Pin.OUT)
# led_y=Pin(4,Pin.OUT)
# led_r=Pin(6,Pin.OUT)
# def temp_range(temp):
# if temp>=10 and temp <=33:
# return 0
# return 1
# def adc_to_temp(adc_value):
# temp=1/((math.log(1/((65535/adc_value)-1)))/3950 + 1/298.15)-273.15
# return temp
# temp_out_of_range_start=None
# def fn(timer):
# global temp_out_of_range_start
# adc_value = A0.read_u16()
# temp_celsius = adc_to_temp(adc_value)
# lcd.clear()
# lcd.putstr(str(temp_celsius))
# if temp_range(temp_celsius):
# led_y.on()
# temp_out_of_range_start = None
# else:
# led_y.on()
# led_g.off()
# led_r.off()
# #when temp_out_of_range value is set
# if utime.time() - temp_out_of_range_start > 5:
# led_g.off()
# led_r.on()
# lcd.clear()
# lcd.putstr("DANGER!")
# utime.sleep(1)
# timer=Timer(freq=1,mode=Timer.PERIODIC,callback=fn)