import time
from machine import ADC, Pin
import math
sensor = ADC(Pin(26))
button = Pin(22, Pin.IN, Pin.PULL_UP)
led = Pin(27, Pin.OUT)
def read():
analog = sensor.read_u16()
Beta = 3950
celsius = 1 / (math.log(1 / (65535 / analog - 1)) / Beta + 1.0 / 298.15) - 273.15;
return celsius
while True:
led.toggle()
temp = read()
if button.value(1):
print("temperature: {:.1f} c".format(temp))
else:
print("")
time.sleep(1)
read()