from machine import Pin
from utime import sleep, ticks_ms, ticks_diff
led = Pin(0, Pin.OUT) # FIXED PIN
button = Pin(14, Pin.IN, Pin.PULL_UP) # FIXED
intervals = [0.5, 1, 2]
flag = 0
last_state = 1
last_press_time = 0
debounce = 200 # ms
while True:
current = button.value()
# detect press (HIGH → LOW)
if last_state == 1 and current == 0:
now = ticks_ms()
if ticks_diff(now, last_press_time) > debounce:
flag = (flag + 1) % 3
print("New interval:", intervals[flag])
last_press_time = now
last_state = current
led.toggle()
sleep(intervals[flag])