from machine import Pin, ADC, PWM
import time
from dht import DHT22
bot = Pin(4,Pin.IN,Pin.PULL_UP)
pir = Pin(22,Pin.IN)
pot = ADC(28)
buzzer = PWM(17)
d22 = DHT22(27)
def mov(args):
l_pot = pot.read_u16()
print(f"Leitura do potênciometro {l_pot}")
buzzer.freq(285)
buzzer.duty_u16(800)
time.sleep(1)
def pressionado(args):
try:
d22.measure()
T = d22.temperature()
U = d22.humidity()
except:
print('Falha na leitura.')
resp = int(input('Digite 1 para ler Temperatura, 2 para ler Umidade ou 3 para ler Ambos: '))
if resp == 1:
# temp
print(f"Temperatura {T}")
elif resp == 2:
# umidade
print(f"Umidade: {U}")
elif resp == 3:
# ambos
print(f"Temperatura {T} e Umidade {U}")
else:
print("Opção Inválida")
pir.irq(trigger=Pin.IRQ_RISING, handler=mov)
bot.irq(trigger=Pin.IRQ_FALLING, handler=pressionado)
while True:
buzzer.duty_u16(0)
print("\nPressione o botão ou mova-se")
time.sleep(1)