from machine import Pin
from utime import sleep
# --- Setup Pins ---
led = Pin(15, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_DOWN) # Internal pull-down resistor
# --- State Variable ---
led_state = False
# --- Main Loop ---
while True:
if button.value() == 1: # Button is pressed
led_state = not led_state # Toggle LED state
led.value(led_state) # Apply new state to LED
sleep(0.3) # Debounce delay to avoid multiple toggles