LED GURUcosycom.com
PAGE 120 OF 150 · MICROCONTROLLERS & LEDS

Simple LED Sequencer Program

An array of patterns can be stepped through in a loop.

LED SYMBOLTriangle points from anode to cathode; the arrows show light leaving the part.

Pattern table

A sequencer stores each pattern as a number where every bit is one LED, such as 00000001 for the first LED. Step through the table to produce chases, alternations and bounces.

Program steps

  • Put patterns in an array.
  • Show the pattern at the current step.
  • Move on when the step time has passed, using the millis counter.
  • Use a button to switch between pattern sets.

Keeping patterns as data instead of code makes new effects as easy as adding another row.

REMEMBER
Treat patterns as data, not code.

Try it yourself

Sketch the circuit on paper first, calculate the values, then build it on a solderless breadboard using a low-voltage supply. Measure with a multimeter before you make anything permanent.

Explore LED clocks, stopwatches and electronics at cosycom.com.

Watch: COSYCOM channel videos

www.youtube.com/@cosycom