from machine import Pin
import time
# Setup the LED and button
led = Pin(2, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_UP)
# Function to check button state and control LED
def control_led():
while True:
time.sleep(0.5)
if button.value() == 0: # Button pressed (active-low)
time.sleep(0.5) # ❌ Intentional bug: delay before turning on LED
led.value(1) # LED turns on late
else:
led.value(0) # LED off when not pressed
# Run the control_led function
control_led()