from machine import Pin
import time
switch = Pin(4, Pin.IN)
led = Pin(2, Pin.OUT)
while True:
switch_state = switch.value()
print("Switch state :", switch_state)
if switch_state == 1 :
led.value(1)
else:
led.value(0)
time.sleep(0.1)