from machine import Pin import time # turn on two falling-edge interrupts # use interrupts to count the number of times # button 15 and 14 are pressed flag1 = 0 flag2 = 0 N1 = 0 N2 = 0 pin1 = Pin(15,Pin.IN,Pin.PULL_UP) pin2 = Pin(14,Pin.IN,Pin.PULL_UP) def player1(pin1): global flag1 global N1 flag = 1 N1 = N1 + 1 def player2(pin2): global flag2 global N2 flag2 = 1 N2 = N2 + 1 # options are RISING, FALLING, LOW_LEVEL, HIGH_LEVEL pin1.irq(trigger=Pin.IRQ_FALLING, handler=player1) pin2.irq(trigger=Pin.IRQ_FALLING, handler=player2) Time = 0.0 while (Time < 10): print(Time, N1, N2) Time += 0.1 time.sleep(0.1)