# import functions & libraries
import micropython
from machine import Pin, Timer
from time import sleep_ms, ticks_ms, ticks_diff
from debounce import debounce
# Allocate emergency exception buffer
micropython.alloc_emergency_exception_buf(100)
# setup LED and button
rled = Pin(9, Pin.OUT, value=0)
btn = Pin(6, Pin.IN, Pin.PULL_UP)
# delay value
delay = 1000
# ISR button (callback)
def btn_callback(btn):
    global delay
    if debounce(): 
        return
    if delay == 1000:
        delay = 250
    else:
        delay = 1000      
# Programme
print("Start")
btn.irq(trigger=Pin.IRQ_FALLING, handler=btn_callback)
while True:
    try:
        rled.on()
        sleep_ms(delay)
        rled.off()
        sleep_ms(delay)
    except KeyboardInterrupt:
        break
rled.off()
print("Finished.")