# add the needed libraries (digital io is used to control input and output device)
import board, time, digitalio
# Setup the LED library object
Gled = digitalio.DigitalInOut(board.GP10) # setup the pin name for the led
Gled.direction = digitalio.Direction.OUTPUT # set the led object as an output device
# Setup the btn
btn = digitalio.DigitalInOut(board.GP26)
btn.direction = digitalio.Direction.INPUT
btn.pull = digitalio.Pull.UP
while True:
if not btn.value: # if button has (send) value (value stands for 1 or high)
Gled.value = True # set the led value to 1 or high
else:
Gled.value = False # else send the value of 0 or low to the LED
time.sleep(0.01) # this called debounce delay, to prevent accidental clicks on the btn