In this project, you will create a 2–player reaction timer game using the BBC micro:bit. The micro:bit will wait a random amount of time, then send a signal. The first player to press their button after the signal wins the round.
The game includes:
button A, Player B uses button B)pin0button_a, button_b, and the LED display in a game.running_time() to measure reaction time.random.randint() to create unpredictable delays.while loops and if statements to control game flow.pin0 (signal)GND (ground)Important: Do not connect the motor directly to the micro:bit pins. Use a transistor, diode, and resistor as recommended in hardware guides.
button_a, Player B uses button_b.best_a stores Player A's best (lowest) reaction time.best_b stores Player B's best (lowest) reaction time.pin0 turns on briefly to give physical feedback on GO and wins.
Set best_A to None // best reaction time for Player A
Set best_B to None // best reaction time for Player B
Define function vibrate(duration_ms):
set pin0 to HIGH
wait duration_ms milliseconds
set pin0 to LOW
Define function countdown():
repeat 3 times:
show small dot in center
wait 0.2 seconds
clear display
wait 0.2 seconds
Scroll "REACTION 2P" on the display
Forever:
Scroll "A/B=START"
// Wait for either player to start the round
While button A is NOT pressed AND button B is NOT pressed:
small pause
Clear the display
Scroll "GET READY"
Call countdown()
// Choose a random delay between 1000 and 4000 ms
delay = random number between 1000 and 4000
false_starter = NONE
start_delay_time = current running_time()
// Check for false starts during the delay
While current_time - start_delay_time < delay:
If button A is pressed:
false_starter = "A"
break out of this loop
If button B is pressed:
false_starter = "B"
break out of this loop
small pause
If false_starter is NOT NONE:
show "NO" icon on display
play error sound
vibrate for a short time
If false_starter is "A":
scroll "A FALSE"
scroll "B WINS!"
Else:
scroll "B FALSE"
scroll "A WINS!"
// Show current high scores
If best_A is None:
scroll "A BEST: ---"
Else:
scroll "A BEST: " + best_A + "ms"
If best_B is None:
scroll "B BEST: ---"
Else:
scroll "B BEST: " + best_B + "ms"
scroll "B=RESET"
// Wait a few seconds or until B presses reset
Wait up to 5 seconds for button B press
Clear display
Go back to the start of the main loop
// No false start happened
Show happy face on display
play "GO" sound (for example, a simple note)
vibrate for a short time
start_time = running_time()
winner = NONE
// Wait for first player to react
While winner is NONE:
If button A is pressed:
winner = "A"
Else if button B is pressed:
winner = "B"
small pause
end_time = running_time()
reaction_time = end_time - start_time
Clear display
If winner is "A":
scroll "A WINS!"
scroll reaction_time + "ms"
vibrate briefly
play victory sound
// Update high score for A
If best_A is None OR reaction_time < best_A:
best_A = reaction_time
scroll "A NEW BEST!"
Else (winner is "B"):
scroll "B WINS!"
scroll reaction_time + "ms"
vibrate briefly
play victory sound
// Update high score for B
If best_B is None OR reaction_time < best_B:
best_B = reaction_time
scroll "B NEW BEST!"
// After each round, show both players' best times
If best_A is None:
scroll "A BEST: ---"
Else:
scroll "A BEST: " + best_A + "ms"
If best_B is None:
scroll "B BEST: ---"
Else:
scroll "B BEST: " + best_B + "ms"
scroll "B=RESET"
// Wait for reset or timeout
Wait up to 5 seconds for button B press
Clear the display
// Loop back to the beginning (next round)
The name of the file will be:
PX_lastname_React
PX_lastname_React.png — Screenshot inside Python editor showing your code.PX_lastname_React.py — Your Python source file.PX_lastname_React.txt — Plain-text copy of your code.PX_lastname_React.hex — Hex file to run on the physical micro:bit.PX_lastname_React.mp4 — Short demo video of the program running on the board.