← Teacher guide

Reaction timer

Students build a reaction game from an almost empty starter in three milestones, using a random wait, running time, a true/false variable, decisions and a best score.

micro:bit: talk and play · Final challenge: Reaction duel · about 55 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict, Run, Investigate 12 min · Milestone 1 12 min · Milestone 2 12 min · Milestone 3 14 min · Why random 5 min

Before class

This challenge adds nothing new: every part was taught earlier in the course. Time between gave the timing (store running time in start, then running time − start); True or false gave waiting, the flag that catches early presses. The milestones fade the help: Milestone 1 lists the steps, Milestone 2 gives only the goal, Milestone 3 only goals. Play it yourself first; good times are 200 to 400 ms, and the simulator adds a little delay.

Running the lesson

  1. Predict and Run: the random wait is what makes it a reaction game. Let students try to guess and fail.
  2. Investigate: matching jobs to blocks is the plan for the milestones.
  3. Milestone 1: if times look huge, start was never set.
  4. Milestone 2: waiting is true only while the heart shows. Read the A event aloud: 'if we are waiting for a press, time it; else, too early'.
  5. Milestone 3: starting best at 99999 means any first time beats it.
  6. Why random: a fixed wait can be counted, so it stops measuring reactions.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

Putting the parts in the right events. Ask which event each job belongs in: B or A.

When students get stuck

What you will seeA question to askThe fix
The time shown is huge, like 15000.When is start set?Set start to running time straight after the heart is shown.
Every press shows a cross.Where is waiting set to true?Set waiting to true after the heart appears (after start is set).
The best time never changes, or is always the latest time.What is best at the start, and which way round is your comparison?Start best at 99999, and use if reaction < best.

Answers to the checks

  1. Predict: You press B three times, waiting for the heart each time. Does the heart take the same time to appear each time?
    A different time each time. pick random chooses a new wait from 1000 to 4000 ms on every press.
  2. Jobs and blocks: This is the finished game. Match each job with the blocks that do it.
    wait an unguessable time → B. pause pick random 1000 to 4000; measure the reaction → A. running time − start; catch an early press → C. if waiting … else; keep the fastest time → D. if reaction < best, set best to reaction
  3. Trace the times: start is set when the heart appears. Fill in the number shown when A is pressed.
    250, 320
    The number shown is running time minus start: how many milliseconds passed between the heart and the press.
  4. The best time: best starts at 99999. Your first reaction is 400. What is best after it?
    400
    400 is less than 99999, so best becomes 400. Starting best very high means any first time beats it.
  5. Why random?: In this version the wait is always 2 seconds. Why does that spoil the game?
    Players learn the timing and press without reacting to the heart
    A fixed wait can be counted. A random wait can only be reacted to, so it measures reactions.

Solutions

One possible solution for each task. Other correct programs are fine.

Milestone 1: time the press

The program as blocks
Show as code
let start = 0
input.onButtonPressed(Button.B, function () {
    basic.clearScreen()
    basic.pause(randint(1000, 4000))
    basic.showIcon(IconNames.Heart)
    start = input.runningTime()
})
input.onButtonPressed(Button.A, function () {
    basic.showNumber(input.runningTime() - start)
})

Milestone 2: no cheating

The program as blocks
Show as code
let waiting = false
let start = 0
input.onButtonPressed(Button.B, function () {
    waiting = false
    basic.clearScreen()
    basic.pause(randint(1000, 4000))
    basic.showIcon(IconNames.Heart)
    start = input.runningTime()
    waiting = true
})
input.onButtonPressed(Button.A, function () {
    if (waiting) {
        waiting = false
        basic.showNumber(input.runningTime() - start)
    } else {
        basic.showIcon(IconNames.No)
    }
})

Milestone 3: beat your best

The program as blocks
Show as code
let reaction = 0
let waiting = false
let start = 0
let best = 99999
input.onButtonPressed(Button.B, function () {
    waiting = false
    basic.clearScreen()
    basic.pause(randint(1000, 4000))
    basic.showIcon(IconNames.Heart)
    start = input.runningTime()
    waiting = true
})
input.onButtonPressed(Button.A, function () {
    if (waiting) {
        waiting = false
        reaction = input.runningTime() - start
        basic.showNumber(reaction)
        if (reaction < best) {
            best = reaction
            basic.showIcon(IconNames.Happy)
        }
    } else {
        basic.showIcon(IconNames.No)
    }
})
input.onButtonPressed(Button.AB, function () {
    basic.showString("Best")
    basic.showNumber(best)
})

Why random?

Open task: any program that does what the step asks.

Stretch and support

Stretch: Show a rating after each time: under 250 a happy face, under 400 a meh face, otherwise a sad face (if, else if, else).

Support: Give students last lesson's no-cheating program as their Milestone 1 starter, and focus on Milestone 3.

Exit ticket

Why does the game need waiting? What would happen without it?

Without it, pressing A before the heart still shows a number, so players could cheat by pressing early.

What each step is for

Where it leads

Next: Radio duel, the same game for two players over radio. Class ideas: a class reaction leaderboard on the board; does reaction time change after exercise? (a quick science investigation with real micro:bits).