Microbit
Beginner
40 mins
Teacher/Student led
+140 XP

Studio: Reaction Time Tester in Python

Students use PRIMM to build a micro:bit reaction time tester in Python, working with variables, loops, lists and conditionals, then compare the text build with the block version they already know.

Teacher Class Feed

Load previous activity

    1 - Start: What We're Building ~4 mins

    Illustration for Start: what we're buildingToday you are coding in Python on the micro:bit.

    You can already make sprites move and build simple games with blocks. Now you will build a Reaction Time Tester step by step: predict first, then build, run and fix.

    By the end you will have a game that waits a random time, measures how fast you press, and keeps your best scores. You will also think about what felt easier in blocks and what felt easier in text.

    2 - Introduction to the Game ~3 mins

    In this lesson, you'll build a Reaction Time Tester game using your Micro:bit. The game will measure how quickly you press a button after a random LED lights up. You'll use timers within loops to calculate reaction time, store high scores in a list, compare times using if statements inside functions, and display results with string formatting. This reinforces core Python concepts in a fun, competitive challenge.

    By the end of this lesson, you'll have a game that tracks and displays your best reaction times. Open the Micro:bit Python editor at python.microbit.org and start a new project.

    Remember to test your code frequently by running it in the simulator. The game will respond to button presses on the virtual Micro:bit.

    3 - Import Modules ~2 mins

    In this step, we'll import the necessary modules. We need the microbit module for hardware access, the random module for random delays, and we'll use time for timing, but since Micro:bit uses running_time() for timers, we'll handle that later.

    Start by adding the following complete code to your editor:

    from microbit import *
    import random
    This imports everything from microbit and the random module. Run the code; nothing will happen yet, but it should run without errors.

    4 - High Scores List and Game Loop ~3 mins

    Next, we'll create a list to store high scores (initially empty) and display a 'Press A to start' message to start the game. Lists are perfect for holding multiple scores, and we'll add to it later. We'll also add in a loop for the code for the game.

    Update your code to the following complete version:

    from microbit import *
    import random
    
    high_scores = []
    display.scroll("Press A to start", delay=50)
    
    while True:
        while not button_a.is_pressed():
            sleep(100)
    Avoid copy-pasting the code. Type each line to master the code’s logic and structure. This hands-on approach will pay off when you’re tackling exams and real-world coding challenges.
    Run the code. You should see 'Press A to start' scroll on the display. The list high_scores is now set up to store times.
    The inner while loop waits for button A to be pressed, checking every 100 milliseconds to avoid constant CPU usage.

    5 - Add a Random Delay ~2 mins

    Now, let's add a random delay before lighting up an LED (by showing an image). This sets up the 'wait' period before the signal to react.

    We'll use sleep(random.randint(1000, 5000)) for a random wait between 1-5 seconds. Then show Image.YES as the 'go' signal.

    Update your code to this complete version:

    from microbit import *
    import random
    
    high_scores = []
    display.scroll("Press A to start", delay=50)
    
    while True:
        while not button_a.is_pressed():
            sleep(100)
    
        display.clear()
        sleep(random.randint(1000, 5000))
        display.show(Image.YES)
    
    Run the code. Press A to start, the display clears, and after a random delay, it shows the YES image.
    This adds a random delay using random.randint and displays Image.YES as the go signal.

    123learn · Online learning platform

    Unlock the full learning experience

    You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.

    Hundreds of curriculum-aligned lessons
    Interactive activities in every lesson
    Printable resources & progress tracking
    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2025. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more