from machine import Pin
led_pin = Pin(22, Pin.OUT)
button_pin = Pin(15, Pin.IN, Pin.PULL_DOWN) # Replace with your button pin
# If your button circuit does not include an external pull-down resistor, you should enable the internal pull-down resistor using Pin.PULL_DOWN.
button_pin = Pin(15, Pin.IN) # use this if you are using pull down resistor
while True:
if button_pin.value() == 1: # Button pressed
led_pin.value(1)
else:
led_pin.value(0)