from machine import Pin
from time import sleep
# Define GPIO pins for switches and LEDs
left_switch = Pin(2, Pin.IN) # Left switch (GP-2) as input
right_switch = Pin(3, Pin.IN) # Right switch (GP-3) as input
left_led = Pin(14, Pin.OUT) # Left LED (GP-14) as output
right_led = Pin(17, Pin.OUT) # Right LED (GP-17) as output
while True:
left_state = left_switch.value() # Read left switch state
right_state = right_switch.value() # Read right switch state
if left_state == 1 and right_state == 0: # If only left switch is ON
left_led.value(1) # Turn ON left LED
sleep(0.5) # Wait 0.5 seconds
left_led.value(0) # Turn OFF left LED
sleep(0.5) # Wait 0.5 seconds
elif left_state == 0 and right_state == 1: # If only right switch is ON
right_led.value(1) # Turn ON right LED
sleep(0.5) # Wait 0.5 seconds
right_led.value(0) # Turn OFF right LED
sleep(0.5) # Wait 0.5 seconds
else: # If both switches are ON or both switches are OFF
left_led.value(0) # Keep left LED OFF
right_led.value(0) # Keep right LED OFF
sleep(0.1) # Small delay