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
Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
WorksheetOpen in PrintDownload Print the student copy; the Teacher edition has the answers.
Students will be able to
I can plan a program as an ordered loop.
I can time an event with millis().
I can test a design for unfair or unexpected use.
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:
A Inquiring and analysing: the brief, its criteria and constraints, and research into parts (Inquire).
B Developing ideas: a design specification, the circuit and code plan, and the test table written before building (Develop).
C Creating the solution: building it (in the simulator, then for real), following the plan and justifying changes (Create).
D Evaluating: testing against the specification, recording failures, improvements and impact (Test, Evaluate).
Otherwise, use the same four headings as a simple rubric: each step's reflect checks are the evidence list.
Running the lesson
Develop: ask how the game could know about a press during the wait.
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 see
A question to ask
The 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
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.
Two ways to do it: Two ideas for the wait. A: wait with delay() for a random 2 to 5 seconds, then light the LED. B: keep checking the button while waiting, using millis(). Which can catch a false start? B: delay() stops it watching the button While delay() runs, the sketch does nothing else, so it can't see an early press. A millis() loop keeps checking the button the whole time it waits.
Your own two ideas: Now two ideas of your own. For each one, say which criterion in the brief it's strongest on and which it's weakest on. Then say which you'll build, and why. One way to write it: Idea 1: B's millis() loop, with the time on the serial monitor. Strongest on false starts: it watches the button the whole time. Weakest on explaining itself without a laptop. Idea 2: the same loop with an LCD. Strongest for a lunchtime game nobody has to set up. Weakest on parts: more wiring to go wrong. I'll build idea 1 first, because catching false starts is the hard criterion, then add the LCD once every test passes.
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.
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.
Another team's results: Another team's game: ten rounds with waits from 2.1 to 4.9 s and times of 190 to 320 ms; three deliberate false starts, two caught and one shown as a time of 0 ms. Which criterion fails? False starts: the one shown as 0 ms wasn't caught A time of 0 ms means the early press counted as a go. The brief says false starts must be caught, so one miss fails it. Next: when in the wait did that press happen?
Fix and re-test: Pick one test that failed. Write what happened, what caused it, what you changed, and what the test showed when you ran it again. One way to write it: Test: false start 3. What happened: it showed 0 ms instead of "Too soon!". Cause: I only checked for an early press once, at the start of the wait, so a press near the end slipped through; I checked by pressing late on purpose. Change: check the button on every pass of the waiting loop. Re-test: ten more false starts at different times, all caught, and the ten normal rounds still fine.
Which is evidence?: Which is the strongest evidence that the design meets a criterion? A planned test with its recorded result A planned test from your table sets the input the criterion is about and records what happened; that 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
Inquire: the brief: Separating what the design must do (criteria) from the limits it works within (constraints) is the first move of any design brief.
Develop: two ideas first: Comparing two concepts against the brief's criteria before planning one gives the range of ideas the Develop stage asks for (MYP Design B), and makes the choice something a student can defend.
Develop: plan before you build: Putting the game loop in order and tracing its timing plans the logic; the false-start check is the part most designs forget.
Create: build it: Building in the simulator first catches wiring and code slips cheaply; the real build then tests the design against the world.
Test: run your table: Judging another team's results against the brief first, then running the test table written in Develop and writing up one failure, is the evidence for the evaluation.
Evaluate: against the brief: Judging the design criterion by criterion, with evidence from the tests, is what separates an evaluation from a description.
Where it leads
Other Years 8–9 projects: Smart plant monitor, Parking assistant.