Week 4 · Timing & Evidence

Session 16: Timing without delay()

Teach & build120 minLesson 11: Non-Blocking Timing & State Machines

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.

  1. Lesson 11: Why delay blocks
  2. Lesson 11: The millis pattern
  3. Lesson 11: Independent timers
  4. Theory Reference: millis()

Session plan

  1. 0:0010 min
    Recap

    Quiz: buttons and debounce

  2. 0:1020 min
    Demo

    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.

  3. 0:3035 min
    Build

    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.

  4. 1:0545 min
  5. 1:5010 min
    Wrap-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.