LED chaser (running light)

// WHAT YOU WILL LEARN

Put 6 pins in an array (int leds[] = {7, 6, 5, 4, 3, 2}) and use one for loop so leds[i] lights each LED in turn; counting starts at 0.

// LESSON NOTES

6 LEDs + 1 for loop = a running light 🔴

WIRING: 6 red LEDs on pins 7, 6, 5, 4, 3, 2. Each one gets its own 220 Ω resistor (5 V − 2 V = 3 V, 3 V ÷ 220 Ω ≈ 14 mA) and they all share one GND.

THE ARRAY: int leds[] = {7, 6, 5, 4, 3, 2}; keeps all 6 pins in one name. leds[0] is pin 7, leds[5] is pin 2. Counting starts at 0!

THE for LOOP: i goes 0, 1, 2 … 5, so leds[i] picks each LED in turn: ON, wait 100 ms, OFF. 3 lines light up all 6 LEDs.

Want it to run the other way? Just flip the order of the list.

Related lessons