from machine import Pin
import time
import urandom
led = Pin(15, Pin.OUT)
btn = Pin(16, Pin.IN, Pin.PULL_UP)
print("=== REACTION TIMER GAME ===")
print("Wait for LED...")
print("Press button when LED turns ON\n")
while True:
time.sleep(urandom.uniform(2, 5)) # Random delay
led.on()
start_time = time.ticks_ms()
while btn.value(): # Wait for your press
pass
reaction_time = time.ticks_diff(time.ticks_ms(), start_time)
led.off()
print("Your reaction time:", reaction_time, "milliseconds\n")
time.sleep(2)