import machine
import time
# Initialize the onboard LED(GP22) as output
led = machine.Pin("GP22", machine.Pin.OUT)
# Initialize a button (GP1) as input with pull-down resistor
button = machine.Pin("GP1", machine.Pin.IN, machine.Pin.PULL_DOWN)
last_press = 0
debounce_delay = 50 # ms
while True:
now = time.ticks_ms()
if button.value() and time.ticks_diff(now, last_press) > debounce_delay:
last_press = now
led.value(1) # Turn on
time.sleep(1)
led.value(0) # Turn off
time.sleep(1)
led.value(0) # Ensure LED stays off when not pressed