# El objetivo del programa es crear un juego donde se mide el
# tiempo de reacción al pulsar un botón cuando se apaga el LED
#
#
#
#-----------------------MICROPYTHON----------------------------
#
#
#
#
# Hecho por Rodrigo González Quidiello
import machine
import utime
import urandom
from lcd1602 import LCD
led = machine.Pin(9,machine.Pin.OUT)
play_button = machine.Pin(15,machine.Pin.IN,machine.Pin.PULL_UP) #BOTÓN ROJO
button = machine.Pin(16,machine.Pin.IN,machine.Pin.PULL_UP) #BOTÓN AZUL
lcd = LCD()
def button_handler(pin):
button.irq(handler=None)
timer_reaction = utime.ticks_diff(utime.ticks_ms(), timer_start)
print("Your reaction time was " + str(timer_reaction) + " milliseconds!")
message = str(timer_reaction) + " ms "
lcd.message('Your reaction\ntime was ' + message)
while True:
lcd.message('Press red button\nto play ')
if play_button.value() == 0:
lcd.clear()
lcd.message('Blue button when\nLED turns off')
led.on()
utime.sleep(urandom.uniform(5,10))
led.off()
lcd.clear()
timer_start = utime.ticks_ms()
button.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_handler)
utime.sleep(10)
lcd.clear()