from machine import ADC
from time import sleep, ticks_us, ticks_diff
T1 = ticks_us()
Sensor = ADC(4)
tempo_ref = 0.00002 # 20 microssegundos
def ler_temperatura():
global T1
T2 = ticks_us()
diferenca = ticks_diff(T2, T1) / 1_000_000
leitura = (Sensor.read_u16() * 3.3) / 65535
temperatura = 27 - (leitura - 0.706) / 0.001721
if diferenca >= tempo_ref:
print(f"Temperatura atual é: {temperatura:.2f}°C")
T1 = T2
while True:
ler_temperatura()