# Source: Electrocredible.com, Language: MicroPython
from machine import Pin
import time
interrupt_flag=0
debounce_time=0
falling = Pin(5, Pin.IN, Pin.PULL_UP)
rising = Pin(6, Pin.IN, Pin.PULL_UP)
led = Pin("LED", Pin.OUT)
count=0
def callbackFALLING(falling):
global interrupt_flag, debounce_time
if (time.ticks_ms()-debounce_time) > 100:
interrupt_flag= 1
debounce_time=time.ticks_ms()
def callbackRISING(rising):
global interrupt_flag, debounce_time
if (time.ticks_ms()-debounce_time) > 100:
interrupt_flag= 2
debounce_time=time.ticks_ms()
falling.irq(trigger=Pin.IRQ_FALLING, handler=callbackFALLING)
rising.irq(trigger=Pin.IRQ_RISING, handler=callbackRISING)
while True:
if interrupt_flag is 1:
interrupt_flag=0
print("Interrupt falling")
led.toggle()
if interrupt_flag is 2:
interrupt_flag=0
print("Interrupt rising")
led.toggle()