from machine import Pin # import Pin class
import time # import time module
# create pin object from Pin5, set Pin5 to input
pin = Pin(5, Pin.IN, Pin.PULL_UP)
led = Pin(25, Pin.OUT) # create pin object from Pin25, set Pin25 to output
interrupt_flag = 0 # global variable
debounce_time = 0 # global variable
count = 0 # global variable
def callback(pin): # callback function
global interrupt_flag, debounce_time # global variable
if (time.ticks_ms()-debounce_time) > 500: # if time difference more than 500 milliseconds
interrupt_flag = 1 # set interrupt_flag to 1
debounce_time = time.ticks_ms() # get current time
pin.irq(trigger=Pin.IRQ_FALLING, handler=callback) # set interrupt handler
while True: # create an infinite loop
if interrupt_flag is 1: # if interrupt_flag is 1
interrupt_flag = 0 # set interrupt_flag to 0
print("Interrupt Detected") # print "Interrupt Detected"
led.toggle() # toggle led