from machine import Pin
import time
# Define the GPIO pin connected to the slide switch
switch_pin = 0 # Change this to the GPIO pin you've connected the switch to
# Initialize the GPIO pin for the switch
switch = Pin(switch_pin, Pin.IN)
while True:
# Read the state of the slide switch
switch_state = switch.value()
# Print the state of the switch
if switch_state == 0:
print("Slide switch is OFF")
else:
print("Slide switch is ON")
# Add a small delay to avoid rapid reading
time.sleep(0.1)