I made this testing of a PIR Sensor (movement) that just turns a LED on, using ISR's.
I just want to share it with you and ask if this interrupt is well implemented, and else how can it be improved.
Code: Select all
from machine import Pin from time import sleep motion = False def handle_interrupt(pin): #Avoid using print() inside isr global motion motion = True global int_pin int_pin = pin led = Pin(4, Pin.OUT) pir = Pin(14, Pin.IN) pir.irq(trigger = Pin.IRQ_RISING, handler = handle_interrupt) while True: if motion: print('Motion detected! Interrupt on pin:', int_pin) led.on() sleep(5) led.off() print('Motion stopped') motion = False