# import necessary modules
from machine import Pin
import time
# Red LED at GP2 (output pin)
red_led = Pin(2, 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
if switch_state == 1:
red_led.value(1)
else:
# If switch output is LOW (0), turn off RED
red_led.value(0)
# Small delay
time.sleep(0.1)