Week 4 · Timing & Evidence
Session 16: Timing without delay()
Learning outcomes
- Explain why delay() blocks other tasks
- Apply the remember, compare, act, stamp pattern with millis()
- Run two LEDs at independent rates while reading a button
- Store every timestamp as unsigned long
Kit and components
- Uno, two LEDs with 330 Ω resistors, push button, breadboard
- Two-channel oscilloscope
Pre-reading about 25 min
Students read these on their phones before class. They are listed on the student Before class page.
Session plan
- 0:0010 minRecap
Quiz: buttons and debounce
- 0:1020 minDemo
The frozen button
Blink with delay(1000) while pressing a button that should light an LED - it responds late. Rewrite the blink with millis() and show the button responding instantly.
- 0:3035 minBuild
Two timers and a button
Students build the worked sketch and confirm on a two-channel scope that the LEDs have 400 ms and 1400 ms periods running together.
- 1:0545 minCode Along
Time without delay()
- 1:5010 minWrap-up
Remember, compare, act, stamp
Checkpoint: ready to move on?
Each student's sketch runs two LEDs at different rates with no delay(), while button presses still print immediately.
Extension for fast finishers
Add a third timed task that prints the uptime every 2 s (lesson challenge).
Catch-up path
Write the four steps as comments first, then fill in the code under each.
Homework and practice
Code Along 8.3 and 8.4.
Facilitator notes
- This is the most important programming idea in the course: every assessment requires non-blocking timing. Give it the time it needs.