← Teacher guide

Reaction game

A Years 8–9 design project: a fair reaction timer with a random wait, a button and millis(), planned as an ordered loop with a false-start test, built in Tinkercad and optionally on hardware, tested and evaluated.

Capstone projects · Years 8–9: sense and respond · about 150 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

About 3 lessons (around 150 minutes). Inquire part lesson · Develop 1 · Create 1 · Test and evaluate 1

Before class

random(2000, 5001) and millis() are new: give them as a recipe card. A first version with delay() for the wait cannot catch false starts; that limitation is a good Evaluate point and a reason for the millis() version.

If you assess with MYP Design, the steps line up with the criteria:

Running the lesson

  1. Develop: ask how the game could know about a press during the wait.
  2. Test: the class tries to cheat it.

The hard part (on purpose)

The false start is the hard part: it needs the button checked during the wait, not delay(). Let students meet the problem with delay() first.

When students get stuck

What you will seeA question to askThe fix
False starts are never caught.Is the button read while the game is waiting?Wait in a loop that checks millis() and the button, not one long delay().

Answers to the checks

  1. Inquire: the brief: Sort each line of the brief: a criterion (what it must do, which you can test) or a constraint (a limit you must work within)?
    Waits a random 2 to 5 s before lighting → Criterion; Shows the reaction time in ms → Criterion; Catches a press before the light (false start) → Criterion; Kit parts only → Constraint; USB power → Constraint
    Criteria are what you will test at the end; constraints decide what you are allowed to build with.
  2. The loop: Put the game's loop() in order.
    see the program below
    Wait a random time (watching for false starts), light the LED, note millis(), wait for the press, subtract, print.
    waitTime = random(2000, 5001);
    start = millis();
    while (millis() - start < waitTime) { if (digitalRead(2) == HIGH) { falseStart(); return; } }
    digitalWrite(13, HIGH);
    lit = millis();
    while (digitalRead(2) == LOW) { }
    Serial.println(millis() - lit);
    digitalWrite(13, LOW);
    
  3. Timing: The LED lit at millis() = 41200 and the button was pressed at 41487. What is the reaction time in ms?
    287
    41487 − 41200 = 287 ms.
  4. Which is evidence?: Which is the strongest evidence that the design meets a criterion?
    A test from the table that set the input and recorded the expected result
    A planned test with a recorded result is evidence; everything else is a feeling.

Stretch and support

Stretch: Keep the best time of the session, and show a two-player result.

Support: A recipe card for random and millis, and the loop with the false-start check given.

Exit ticket

Why can't a reaction game use a single delay() for its random wait?

Nothing is read during a delay, so a press before the light (a false start) can't be caught.

What each step is for

Where it leads

Other Years 8–9 projects: Smart plant monitor, Parking assistant.