#Importando as bibliotecas necessárias
from machine import Pin
from utime import sleep
from dht import DHT22
#Declarando as variáveis
ledvermelho = Pin(2,Pin.OUT)
ledazul = Pin(3, Pin.OUT)
ledverde = Pin(4, Pin.OUT)
botao = Pin(5,Pin.IN, Pin.PULL_UP)
sensor = DHT22(6)
while True:
ledvermelho.off()
ledazul.off()
ledverde.off()
if botao.value() == 0:
pergunta = int((input("Você deseja ler:\nTemperatura (1) \n" "Umidade(2) \n" "Ambos?(3) \n")))
try:
sensor.measure()
temperatura = sensor.temperature()
umidade = sensor.humidity()
except:
print('Falha no sensor')
if pergunta == 1:
print(temperatura)
ledvermelho.on(), ledazul.off(), ledverde.off()
sleep(1.5)
elif pergunta == 2:
print(umidade)
ledazul.on(), ledvermelho.off(), ledverde.off()
sleep(1.5)
elif pergunta == 3:
print(temperatura,umidade)
ledverde.on(), ledvermelho.off(), ledazul.off()
sleep(1.5)
else:
print('Resposta Inválida')