from machine import Pin
import time
led = Pin(2, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_UP)
state = 0
while True:
if button.value() == 0: # button pressed (active low)
state = not state # toggle LED state
led.value(state)
time.sleep(0.05) # small pause to avoid too-fast toggling