7-Segment Digital Counter
Master the logic of numeric displays. This project demonstrates how to drive a common-cathode 7-segment display using 8 parallel GPIO pins to create a recurring decimal counter.
Project Goal: Map Pico pins GP0 through GP6 to segments A-G and GP7 to the decimal point. Implement a bit-map array to translate integers 0-9 into visual patterns.
1. Wiring Blueprint
| Segment | Pico Pin | Logic | Role |
|---|---|---|---|
| Segment A | GP0 | Active High | Top Bar |
| Segment B | GP1 | Active High | Top-Right Bar |
| Segment C | GP2 | Active High | Bottom-Right Bar |
| Segment D | GP3 | Active High | Bottom Bar |
| Segment E | GP4 | Active High | Bottom-Left Bar |
| Segment F | GP5 | Active High | Top-Left Bar |
| Segment G | GP6 | Active High | Middle Bar |
| Decimal (DP) | GP7 | Active High | Decimal Point |
| COM (Cathode) | GND | Ground | Common Return |
2. JavaScript Implementation
We use a binary map to define which pins should be HIGH for each digit from 0 to 9.
JavaScript (SDK)
import intarva, { Pin, sleep } from 'intarva';
// Initialize the 8-pin array
const segments = [
new Pin('GP0'), new Pin('GP1'), new Pin('GP2'),
new Pin('GP3'), new Pin('GP4'), new Pin('GP5'),
new Pin('GP6'), new Pin('GP7') // DP
];
// Binary Digit Mapping [A, B, C, D, E, f, G, DP]
const digits = {
0: [1, 1, 1, 1, 1, 1, 0, 1],
1: [0, 1, 1, 0, 0, 0, 0, 1],
2: [1, 1, 0, 1, 1, 0, 1, 1],
3: [1, 1, 1, 1, 0, 0, 1, 1],
4: [0, 1, 1, 0, 0, 1, 1, 1],
5: [1, 0, 1, 1, 0, 1, 1, 1],
6: [1, 0, 1, 1, 1, 1, 1, 1],
7: [1, 1, 1, 0, 0, 0, 0, 1],
8: [1, 1, 1, 1, 1, 1, 1, 1],
9: [1, 1, 1, 1, 0, 1, 1, 1]
};
function displayDigit(n) {
const pattern = digits[n] || [0, 0, 0, 0, 0, 0, 0, 0];
for (let i = 0; i < 8; i++) {
segments[i].write(pattern[i]);
}
}
async function run() {
console.log("7-Segment Counter: Initializing...");
while (true) {
for (let i = 0; i <= 9; i++) {
displayDigit(i);
await sleep(1000); // 1-second interval
}
}
}
intarva.on('ready', run);
3. Simulation Result
The following video demonstrates the parallel pin control logic in action, showing the transition between bit-mapped patterns to form a decimal count on the 7-segment display.