# turn LED on or off with button:
# https://RandomNerdTutorials.com/raspberry-pi-pico-outputs-inputs-micropython/
#
# note for Pico 2 users:
# you must connect the button with one leg to GND and the other leg to GPIO15
# and enable the internal pull-up resistor:
# button = Pin(21, Pin.IN, Pin.PULL_UP)
# OR:
# connect one leg to 3.3V and the other leg to GPIO15
# and add and external pull-down resistor between GPIO15 and GND
# and code:
# button = Pin(21, Pin.IN) # without internal pull-up/pull-down
#
# this is because of a hardware issue with the Pico 2 board:
# https://forums.raspberrypi.com/viewtopic.php?t=367462
# https://www.reddit.com/r/raspberrypipico/comments/1k5ax5e/gpio_pin_in_pulldown_not_resetting_pico_2_w/
from machine import Pin
from time import sleep
button = Pin(21, Pin.IN, Pin.PULL_DOWN)
while True:
print(button.value())
sleep(0.5)