Today 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.
Keep this short so time goes on the build. Devices open on python.microbit.org, students logged in. Optional predict before anyone runs code: ask what they think will happen after a random wait when a signal appears and a button is pressed. Do not confirm answers yet. Frame prior knowledge as what they can already do with blocks, not as a named earlier lesson. Pair students for the build if that is your usual routine.
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.
Read the game goal aloud without walking through the full code. Confirm every student has a new blank project in the micro:bit Python editor. Key question: what two buttons will the player use, and which job does each one have? Watch for students jumping ahead into typing before the class is ready. Differentiation: keep hesitant starters with you for the first typed lines.
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 randomModel the two import lines on the board. Students type them; no copy-paste. Run once to show a clean run with no output yet. Common bug: spelling microbit wrong or missing import random. Ask why nothing visible is fine at this stage. Support: dictate the lines slowly; extension pairs can already open the docs tab if curious.
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)
high_scores is now set up to store times.Model the empty high_scores list, the scroll prompt, and the outer loop that waits for button A. Stress that lists hold several scores and the loop keeps the game alive. Common bugs: missing colon after while True, wrong indent on the inner wait, or scrolling text typed with smart quotes. Key question: why do we wait until A is pressed before the round begins?
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)
random.randint and displays Image.YES as the go signal.Add the clear, random sleep and Image.YES signal. Ask students to predict the wait range in seconds before they run. Common bugs: randint bounds swapped or sleep values thought to be seconds not milliseconds; Image.YES misspelled. Circulate and watch pairs press A, wait, and see the signal. Differentiation: support pairs verify the delay feels between about 1 and 5 seconds.
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.