# Toggle LED with Push Button for Raspberry Pi Pico
from machine import Pin
import utime
# Initialize LED and Push Button
led = Pin(19, Pin.OUT)
button = Pin(20, Pin.IN, Pin.PULL_UP)
# Function to toggle the LED state
def toggle_led_state(pin):
led.toggle()
# Attach the function to the button's rising edge
button.irq(trigger=Pin.IRQ_RISING, handler=toggle_led_state)
# Infinite loop to keep the program running
while True:
utime.sleep_ms(10) # Small delay for stability