from machine import Pin, ADC, PWM
import time
import dht
bot = Pin(13, Pin.IN, Pin.PULL_UP)
buzzer = PWM(Pin(18))
sensor_dht = dht.DHT22(Pin(22))
sensor_integrado = ADC(4)
def inicio(args):
resp = int(input("Digite 1 Para Sensor integrado ou 2 Para DHT22: "))
if resp == 1:
try:
leitura = sensor_integrado.read_u16()
except:
print("Erro")
# leitura = 200000
temp_sensor = leitura * 3.3 / 65535
print(f"Temperatura: {temp_sensor}")
buzzer.freq(100)
buzzer.duty_u16(800)
time.sleep(1)
buzzer.duty_u16(0)
elif resp == 2:
try:
sensor_dht.measure()
temp = sensor_dht.temperature()
print(f"Temperatura: {temp}°C")
buzzer.freq(200)
buzzer.duty_u16(400)
time.sleep(1)
buzzer.duty_u16(0)
except:
print("Erro ao ler o sensor DHT22")
else:
print("\nOpção inválida\n")
bot.irq(trigger=Pin.IRQ_FALLING, handler=inicio)
while True:
print("Pressione o Botão\n")
buzzer.duty_u16(0)
time.sleep(5)