# Hungry Hungry Hippo (ver 3) from machine import Pin, Timer import time led = Pin(17, Pin.OUT) tim = Timer() N1 = 0 N2 = 0 GameTime = 0 pin1 = Pin(15,Pin.IN,Pin.PULL_UP) pin2 = Pin(14,Pin.IN,Pin.PULL_UP) def tick(timer): global led global GameTime if(GameTime > 0): GameTime -= 1 led.toggle() else: led.off() def player1(pin1): global N1 N1 = N1 + 1 def player2(pin2): global N2 N2 = N2 + 1 pin1.irq(trigger=Pin.IRQ_FALLING, handler=player1) pin2.irq(trigger=Pin.IRQ_FALLING, handler=player2) # set interrupt time to 10ms tim.init(freq=100, mode=Timer.PERIODIC, callback=tick) GameTime = 1000 while (GameTime > 0): print(GameTime*0.01, N1, N2) time.sleep(0.1)