# import necessary libraries
from machine import Pin
import time
# Red LED at GP2 (output pin)
red_led = Pin(2, Pin.OUT)
# Green LED at GP3 (output pin)
green_led = Pin(3, Pin.OUT)
# Slide switch at GP4
switch = Pin(4, Pin.IN)
while True:
# Read the current state of the slide switch
switch_state = switch.value()
print("Switch State =", switch_state)
# If switch output is HIGH (1), turn on RED LED and turn off GREEN
if switch_state == 1:
red_led.value(1)
green_led.value(0)
else:
green_led.value(1)
red_led.value(0)
# If switch output is LOW (0), turn on GREEN LED and turn off RED
# Small delay
time.sleep(0.1)