from machine import Pin
from time import sleep
motion = False
led = Pin(2, Pin.OUT)
pir = Pin(14, Pin.IN)
def handle_interrupt(pin):
global motion
motion = True
global interrupt_pin
interrupt_pin = pin
pir.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
while True:
# Use motion is always FALSE in this loop
#until interrupt by irq
#if interrupt, then montion TRUE
if motion:
print("Motion detected/ Interrupt by:", interrupt_pin)
led.on()
sleep(20)
led.off()
print('Motion Stopped/')
motion = False
#if no interrupt, then motion FALSE
else:
print('No Motion Detected/')
led.off()
motion = False