Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1.38 KB

File metadata and controls

41 lines (29 loc) · 1.38 KB

Exercise B: multi-LED patterns

Objective

Use arrays and bit masks to animate four LEDs while continuing to read serial input. The sketch replaces long sequences of delay() calls with elapsed-time checks.

Wiring

Pins 2, 3, 4, and 5 each drive one LED through a 220–330 Ω resistor.

Commands

Command Pattern
A all LEDs blink
B scanner / Knight Rider
C alternating pairs
D one-way wave
other off

Verify

Start each pattern, then switch commands mid-animation. The new pattern should start immediately. Leave it running across the millis() rollover only for an extended validation; unsigned elapsed-time arithmetic keeps it safe.

Challenge

Add a pattern by defining a mask array and selecting it in selectPattern(). Avoid adding new digitalWrite() sequences or blocking delays.

Optional progression: ArduinoPatterns

After this lesson works without blocking delays, students may optionally try the companion library ArduinoPatterns. Map the same pin bank and timed masks onto LedBank and LedAnimator, then compare the hand-written Exercise B sketch with the library examples such as ScanningLight and AlternatingPatterns. The course remains complete without the library; the goal is to recognize the abstraction, not to replace the learning exercise.