Reaction Game

by Joshua Henare in Circuits > Raspberry Pi

5 Views, 0 Favorites, 0 Comments

Reaction Game

FK05QVVMPEDVWMY.png

a reaction time game with a start and react button, you press the start button to start the game and when the light turns on you have to react as fast as you can and press the react button

Supplies

1x raspberry pi pico

1x bread board

2x buttons

1x led (any colour)

2x resistors

7x wires

Diagram

Screenshot 2026-05-25 at 12.02.33 pm.png

follow this table and make sure its clean before connecting to your computer

Code

here's the code for the game:


from machine import Pin

import time

import urandom # MicroPython version of random


# Setup

led = Pin(15, Pin.OUT)

start_button = Pin(14, Pin.IN, Pin.PULL_UP)

react_button = Pin(13, Pin.IN, Pin.PULL_UP)


def wait_for_button(pin):

"""Wait until button is pressed"""

while pin.value() == 1: # 1 means not pressed because of pull-up

pass

# Debounce

time.sleep(0.05)

while pin.value() == 0: # Wait for release

pass

time.sleep(0.05)


print("Reaction Time Game with Pico!")

print("Press the START button to begin...")


while True:

print("Waiting for START button...")

wait_for_button(start_button)


print("Get ready...")

led.off()


# Random delay between 2 and 5 seconds

delay = urandom.uniform(2, 5)

time.sleep(delay)


# Signal to react

led.on()

start_time = time.ticks_ms() # Milliseconds precision

print("GO! Press the REACT button now!")


wait_for_button(react_button)

end_time = time.ticks_ms()


reaction_time = (end_time - start_time) / 1000 # Convert to seconds

print("Your reaction time: {:.3f} seconds".format(reaction_time))

time.sleep(2)


led.off()

print("\n--- Next Round ---\n")

Have Fun

make sure all the wires are matching the diagram and have fun