Multi-digit 7-segment displays typically have two or more digits, each of which consists of a 7-segment display by itself. The common lines of each individual digit are used to select the digit to be lit. The driver program uses a technique called “multiplexing”, i.e. lighting one digit at a time very rapidly to display all the digits.

Typical Pin Out

The figure below shows the typical pin-out (i.e. the layout of pins) on a typical 4-digit display. Notice the pins labeled “DIG1” through “DIG4” that are used to activate each digit. Also notice that there is no common LOW (for a common cathode display) or a common HIGH (for a common anode display), unlike that of a single-digit display.

Pinout of 4-digit 7-segment display

Schematic

The schematic (also called “circuit schematic” or “circuit diagram”) shows how a typical 4-digit display is hooked up to an Arduino. Please note that in schematics, the way the pins are represented does NOT necessarily match the pinout of the device.

Circuit Schematic

Circuit Schematic

The Code

Code can be downloaded from GitHub

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// the start of the pins used for A-G - must be sequential
int segmentStart = 2;

// the start of the common pins - must be sequential
int digitStart = 10;

// this code can use either polarity of display.
// true if common is high when ON, otherwise false.
boolean commonAnode = false;

// the number of digits your display has.
int numDigits = 4;

void setup() {
  // Enable all A-G and DP and outputs, 
  // set them to OFF 
  for(int i=0;i<8;++i) {
    pinMode(segmentStart + i, OUTPUT);
    digitalWrite(segmentStart + i, commonAnode?1:0);
  }
  
  // Setup all the common pins, initially OFF.
  for(int i=0;i<numDigits;++i) {
    pinMode(digitStart + i, OUTPUT);
    digitalWrite(digitStart + i, commonAnode?0:1);
  }
}

void loop() {
  // display a number on the 4-digit display.
  int amount = 1234;
  
  for(int i=(numDigits-1);i>=0;--i) {
    // find the current digit, which is in the low 4 bits
    int digit = amount % 10;
    
    writeDigitToDisplay(digit);
    
    // enable the right digit for display
    digitalWrite(digitStart + i, commonAnode?1:0);
    
    // short delay between changes.
    delay(1);
    // Turn of the digit
    digitalWrite(digitStart + i, commonAnode?0:1);
    
    // get the next digit.
    amount = amount / 10;
    
    //rinse, and repeat
  }
}

// Now we define the bits that are on and off
// for each segment, These are used in the
// function below to turn the correct segments on.
int dig[16] = {
// bits     6543210
// digits   abcdefg
          0b1111110,//0
          0b0110000,//1
          0b1101101,//2
          0b1111001,//3
          0b0110011,//4
          0b1011011,//5
          0b1011111,//6
          0b1110000,//7
          0b1111111,//8
          0b1111011,//9
          0b1110111,//a
          0b0011111,//b
          0b1001110,//c
          0b0111101,//d
          0b1001111,//e
          0b1000111 //f
};

void writeDigitToDisplay(int digit) {
  digit = (digit & 0x0f);
  // iterate through each bit
  for(int i=0;i<7;++i) {
    // isolate the current bit in the loop.
    int currentBit = (1<<(6-i));

    // check if the bit is on, and invert for
    // commonhigh if needed.
    int bitOn = (currentBit&dig[digit])!=0;
    if(commonAnode) {
      bitOn = !bitOn;
    }
    
    // and lastly set the bit
    digitalWrite(segmentStart+i, bitOn);
  }
}