from machine import Pin

slider = Pin(2, Pin.IN, Pin.PULL_UP)
relay = Pin(4, Pin.OUT)

while True:
    if slider.value() == 1:
        relay.value(1)
    else:
        relay.value(0)