7-Segment Digital Counter

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 AGP0Active HighTop Bar
Segment BGP1Active HighTop-Right Bar
Segment CGP2Active HighBottom-Right Bar
Segment DGP3Active HighBottom Bar
Segment EGP4Active HighBottom-Left Bar
Segment FGP5Active HighTop-Left Bar
Segment GGP6Active HighMiddle Bar
Decimal (DP)GP7Active HighDecimal Point
COM (Cathode)GNDGroundCommon 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.