from machine import Pin
import time
# Define GPIO pins
led_pin = Pin(15, Pin.OUT)
switch_pin = Pin(14, Pin.IN)
# Main loop
switch_state = 0
led_state = 0
while True:
# initial state
last_state = switch_state
# Read the state of the switch
switch_state = switch_pin.value()
print(switch_state)
# If the switch is ON, turn the LED ON, else turn it OFF
if switch_state == 0 and last_state == 1:
# invert the current state
# if currently is OFF, then ON
# if currently is ON, then OFF
led_state = not(led_state)
led_pin.value(led_state)
#led_pin.on()
# Delay for a short period
time.sleep(0.1)