from machine import ADC, Pin
from neopixel import NeoPixel
from time import sleep_ms
import math
ledinhos = NeoPixel(Pin(19, Pin.OUT), 16)
BETA = 3950
adc = ADC(Pin(2))
adc.atten(ADC.ATTN_11DB)
def read_ntc_temperature():
analog_value = adc.read()
print(analog_value)
temperature_celsius = 1 / (math.log(1 / (4096 / analog_value - 1)) / BETA + 1.0 / 298.15) - 273.15
return temperature_celsius
while True:
temperature = read_ntc_temperature()
if temperature < 25:
cor = (0, 0, 255) #frio
print ("frio")
elif temperature > 40:
cor = (255, 0, 0) #quente
print ("quente")
else:
cor = (0, 255, 0) #morno
print ("morno")
for i in range(16):
ledinhos [i] = cor
ledinhos. write ()
print (f"Temperatura da água: {temperature}")
sleep_ms (2000)