# Actividad 1; Programación de interrupciones
# Marco A. García Márquez; febrero 25, 2024; UTeman DocIA
# Asesor, Dr. Rafael Mota Grajales
# https://wokwi.com/projects/390085761867953153
# https://youtu.be/hvcroC7DYF4
from machine import Pin
import utime
sensor_pir = Pin(28, Pin.IN, Pin.PULL_UP)
sensor_pir2 = Pin(22, Pin.IN)
led = Pin(15, Pin.OUT)
buzzer = Pin(14, Pin.OUT)
def pir(pin):
utime.sleep_ms(300)
if pin is sensor_pir:
print("¡ALARMA! Movimiento detectado en la sala")
sensor_pir.value(Pin.PULL_UP)
elif pin is sensor_pir2:
print("¡ALARMA! Movimiento detectado en la cochera")
for i in range(50):
led.toggle()
buzzer.toggle()
utime.sleep_ms(100)
sensor_pir.irq(trigger=Pin.IRQ_RISING, handler=pir)
sensor_pir2.irq(trigger=Pin.IRQ_RISING, handler=pir)
while True:
led.toggle()
utime.sleep(2)