CNAP

7-Segment Display Reference

Single-digit 7-segment display with two common pins (shared cathode/anode leads) and a decimal point.

Pin names

NameDescription
ASegment A (top)
BSegment B (top-right)
CSegment C (bottom-right)
DSegment D (bottom)
ESegment E (bottom-left)
FSegment F (top-left)
GSegment G (middle)
DPDecimal point
COM.1Common pin 1
COM.2Common pin 2

Attributes

This component has no configurable attributes.

Usage

Connect each segment pin (A–G) through a 220 Ω resistor to a GPIO pin, and tie both COM pins to GND. Drive a segment's GPIO HIGH to light it. To display a digit, set the combination of segments that draws it (see the segment layout below).

  A
 F B
  G
 E C
  D
// Pins: A=2, B=3, C=4, D=5, E=6, F=7, G=8
const int SEG_A = 2, SEG_B = 3, SEG_C = 4, SEG_D = 5;
const int SEG_E = 6, SEG_F = 7, SEG_G = 8;

// Each row: [A, B, C, D, E, F, G]
const bool DIGITS[10][7] = {
  {1,1,1,1,1,1,0}, // 0
  {0,1,1,0,0,0,0}, // 1
  {1,1,0,1,1,0,1}, // 2
  {1,1,1,1,0,0,1}, // 3
  {0,1,1,0,0,1,1}, // 4
  {1,0,1,1,0,1,1}, // 5
  {1,0,1,1,1,1,1}, // 6
  {1,1,1,0,0,0,0}, // 7
  {1,1,1,1,1,1,1}, // 8
  {1,1,1,1,0,1,1}, // 9
};

const int PINS[7] = {SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G};

void showDigit(int d) {
  for (int i = 0; i < 7; i++) {
    digitalWrite(PINS[i], DIGITS[d][i]);
  }
}

void setup() {
  for (int i = 0; i < 7; i++) pinMode(PINS[i], OUTPUT);
}

void loop() {
  for (int d = 0; d <= 9; d++) {
    showDigit(d);
    delay(1000);
  }
}

In real hardware, add a 220 Ω resistor in series with each segment pin. The CNAP simulator does not enforce this.

Examples

DescriptionAttrs
Default display{}

See also

  • Resistor — use one per segment pin in real hardware
  • LED — each segment is functionally a single LED