import board
import digitalio
import time
# LED Output on GP0
led = digitalio.DigitalInOut(board.GP0)
led.direction = digitalio.Direction.OUTPUT
# SW1 Input on GP15 (Pull-Down: Detects HIGH when pressed)
sw1 = digitalio.DigitalInOut(board.GP20)
sw1.direction = digitalio.Direction.INPUT
sw1.pull = digitalio.Pull.DOWN # Enable internal pull-down resistor
# SW2 Input on GP2 (Pull-Down: Detects HIGH when pressed)
sw2 = digitalio.DigitalInOut(board.GP16)
sw2.direction = digitalio.Direction.INPUT
sw2.pull = digitalio.Pull.DOWN # Enable internal pull-down resistor
# --- Main Logic Loop ---
while True:
if sw1.value: # Button SW1 pressed (Logic HIGH)
led.value = True # LED will ON
print("Status: LED ON")
elif sw2.value: # Button SW2 pressed (Logic HIGH)
led.value = False # LED will OFF
print("Status: LED OFF")
# Software Debounce Delay
# Prevents 'contact bounce' where one press looks like multiple triggers
# A 50ms delay ensures the microcontroller ignores these micro-fluctuations
time.sleep(0.05)