Micro:bit Reaction Timer Game

Multiplayer Version with High Scores, Vibration, and False Start

Overview

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:

Learning Objectives

Hardware Requirements

Important: Do not connect the motor directly to the micro:bit pins. Use a transistor, diode, and resistor as recommended in hardware guides.

Game Rules

  1. Either player presses their button (A or B) to start the round.
  2. The screen shows a short "Get Ready" message and a countdown animation.
  3. The micro:bit waits a random time (between about 1–4 seconds) with the LEDs mostly off.
  4. During this random wait:
    • If Player A presses first: Player A false starts, so Player B automatically wins.
    • If Player B presses first: Player B false starts, so Player A automatically wins.
  5. If no one false starts, the micro:bit shows a GO signal (happy face, sound, and vibration).
  6. After the signal, the first player to press their button is the winner.
  7. The micro:bit calculates that player’s reaction time in milliseconds (ms) and displays it.
  8. If that reaction time is better (lower) than the player’s previous best, it becomes their new high score.
  9. The micro:bit shows each player’s high score and then waits for another round.

Key Features & Behavior

Pseudocode – Reaction Timer Game (2 Players)

Top-Level Variables and Setup

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
    

Main Game Loop

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
    

Handling False Starts

    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
    

Normal Start – GO Signal and Reaction Measurement

    // 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!"
    

Displaying High Scores and Reset

    // 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

Files to save on Google Drive under your class and submit to Google Classroom

  1. PX_lastname_React.png — Screenshot inside Python editor showing your code.
  2. PX_lastname_React.py — Your Python source file.
  3. PX_lastname_React.txt — Plain-text copy of your code.
  4. PX_lastname_React.hex — Hex file to run on the physical micro:bit.
  5. PX_lastname_React.mp4 — Short demo video of the program running on the board.

Submission requirements