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.
Pins 2, 3, 4, and 5 each drive one LED through a 220–330 Ω resistor.
| Command | Pattern |
|---|---|
A |
all LEDs blink |
B |
scanner / Knight Rider |
C |
alternating pairs |
D |
one-way wave |
| other | off |
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.
Add a pattern by defining a mask array and selecting it in selectPattern().
Avoid adding new digitalWrite() sequences or blocking delays.
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.