7-segment counter
Seven Arduino pins, one segment per pin, common cathode tied to ground through a 330Ω resistor. The code counts 0 → 9 at one digit every 600 ms.
Segment mapping
A 7-segment display has seven LEDs arranged like this:
aaaa
f b
f b
gggg
e c
e c
dddd
Each segment is wired to an Arduino pin (a → d2, b → d3, ...,
g → d8). The digit table in the code encodes which segments to light
for each number — 3 lights a, b, c, d, g but leaves e and f dark.
One resistor or seven?
Real-world builds use one resistor per segment (7 total) so every segment has the same brightness even when different counts of segments are lit. This lab uses a single shared resistor on the cathode line for schematic simplicity — you'll see a subtle brightness difference between digits that light more segments (like 8) vs fewer (like 1). Fork this and split out seven individual resistors if you want it right.
Try this
- Change
delay(600)to100— fast counter, barely readable. - Flip the order:
n = (n + 9) % 10counts down 9 → 0. - Replace the digit table to draw letters:
b,c,d,E,F,A. Standard hex pattern — handy for a debug display.
Common anode vs common cathode
This lab uses a common-cathode 7-seg (all cathodes tied to GND; a pin is ON when driven HIGH). Common-anode versions flip it: common pin goes to 5 V and a segment lights when the Arduino pin is LOW. Invert the writeDigit logic if you're adapting to a common-anode display.