from machine import Pin
import time
# Define GPIO pins for LED and push button
led_pin = Pin(2, Pin.OUT)
button_pin = Pin(4, Pin.IN, Pin.PULL_UP) # Internal pull-up resistor
# Function to toggle LED state
def toggle_led(pin):
led_pin.value(not led_pin.value())
# Attach interrupt to the push button pin
button_pin.irq(trigger=Pin.IRQ_FALLING, handler=toggle_led)
while True:
# Do other tasks while waiting for button press
time.sleep_ms(100)