from machine import Pin
from time import sleep
# Wait for USB to become ready
sleep(0.1)
print("Practice 1: Smart Toggle Started")
# LED on GP15
led = Pin(15, Pin.OUT)
# Button on GP16 with internal pull-down
button = Pin(16, Pin.IN, Pin.PULL_DOWN)
# State variable (0 = OFF, 1 = ON)
state = 0
#-------------------main-----------------------
while True:
# Detect button press
if button.value() == 1:
state = not state # Toggle state
led.value(state) # Update LED
print("LED State:", state)
# Debounce delay
sleep(0.3)
# Wait until button is released
while button.value() == 1:
pass
sleep(0.05)