from machine import Pin
import time
interruptCounter = 0 # 與主程序通信
totalInterruptsCounter = 0 # 計算中斷事件次數
button = Pin(23, Pin.IN, Pin.PULL_UP)
def button_irq(button):
global interruptCounter # 聲明為全局變量
time.sleep_ms(150)
if button.value() == 1:
interruptCounter = interruptCounter + 1
print('pin change:', button)
print('interruptCounter:', interruptCounter)
while True:
button.irq(trigger = Pin.IRQ_RISING, handler = button_irq)
print('start')
time.sleep(1)