from machine import Pin
import time
led = Pin(16, Pin.OUT)
# Setup button on GP15 as an input with a Pull-Down resistor
button = Pin(27, Pin.IN, Pin.PULL_DOWN)
led.value(0) #start with LED off
print("Click and hold button for LED to glow")
while True:
if button.value() == 1: # If button is pressed (connected to 3.3V)
led.value(1)
#time.sleep(0.5) # Turn LED ON
else:
led.value(0) # Turn LED OFF
#time.sleep(0.5) # Small delay to save CPU power