from machine import Pin
from time import sleep
Led = Pin(15, Pin.OUT)
Button = Pin(16, Pin.IN)
while True:
if Button.value() == 0: # Button is pressed
Led.on() # Turn LED on
while Button.value() == 0:
pass # Wait while the button is held down
Led.off() # Turn LED off once button is released
else:
Led.off() # Ensure LED is off if button is not pressed