from machine import Pin
import utime
import urandom
from song import playsong
from song import player1_victory_song, player2_victory_song
led = Pin(25, Pin.OUT)
player1_button = Pin(15, Pin.IN, Pin.PULL_DOWN)
player2_button = Pin(16, Pin.IN, Pin.PULL_DOWN)
fastest_button = None
def button_handler(pin):
player1_button.irq(handler=None)
player2_button.irq(handler=None)
global fastest_button
fastest_button = pin
led.value(1)
utime.sleep(urandom.uniform(5, 10))
led.value(0)
player1_button.irq(trigger=Pin.IRQ_RISING, handler=button_handler)
player2_button.irq(trigger=Pin.IRQ_RISING, handler=button_handler)
while fastest_button is None:
utime.sleep(1)
if fastest_button is player1_button:
playsong(player1_victory_song)
elif fastest_button is player2_button:
playsong(player2_victory_song)