from machine import Pin
from time import sleep
# Define GPIO pins
led_pin = Pin(2, Pin.OUT)
switch_pin = Pin(14, Pin.OUT)
# Main Loop
while True:
# Initial state
led_pin.off()
# READ THE STATE OF THE SWITCH
switch_state = switch_pin.value()
print (switch_state) # nilai 0 @ 1
# IF THE SWITCH IS ON, TURN THE LED ON
if switch_state == 1:
led_pin.on()
# DELAY FOR A SHORT PERIOD
sleep(0.1)