from machine import Pin
import time
# Initialize global counter
counter = 0
# Define the interrupt service routine
def isr(pin):
global counter
counter += 1
print('Button pressed count:', counter)
# Setup the button input and attach the ISR
button = Pin(32, Pin.IN, Pin.PULL_UP)
button.irq(trigger=Pin.IRQ_FALLING, handler=isr)
# Run an infinite loop to keep the program running
while True:
time.sleep(1) # sleep to reduce CPU usage