from machine import Pin
from utime import sleep
# Define LED and button
led = Pin(5, Pin.OUT) # LED on GP15
button = Pin(14, Pin.IN, Pin.PULL_DOWN) # Button on GP14 with pull-down resistor
# Main loop
while True:
if button.value() == 1: # Button is pressed
led.on() # Turn on the LED
sleep(2) # Wait for 2 seconds
led.off() # Turn off the LED
else:
led.off() # Keep LED off if button is not pressed