how to use a 4-digit seven segment display ??

I'm trying to use a four digit seven segment display. it has 8 cathode pins, each corresponds to a segment on a number and a decimal dot. there are 4 anode pins, each corresponds to a digit (i.e. it is common anode). The other 4 pins are for a colon (and other LEDs on the display that I don't really care ..).

I found a circuit diagram, like this:


Here are my questions:

  1. refer to the image above. If I want to display two different numbers, for example, 3 and 0, on the first two digits. Obviously, some segments will need to be turned ON on one digit and OFF on the other digit. Because I want to use the first two digits, I will have pin 1 and 2 HIGH. Then If I want segment A turned ON on the first digit but OFF on the second digit, seems that I won't be able to do that. If I have pin 14 LOW, that segment will be turned ON on both digits. so how exactly are people using these display?

  2. I tried to find sample codes, but I don't quite understand those codes (I'm a beginner). If you have a sample codes and can give me a link/ post it here, I would be really appreciate that.

  3. I looked up some sample projects and a lot of them use transistors .. Why? Do I have to use transistors?


You have two options, both involve multiplexing.
The first way requires no additional hardware but uses more software.
Your code will have a loop within a loop.
The outer loop will cycle thru the anodes, the inner loop will cycle thru cathodes.
Persistance of Vision will trick the eye into seeing more than 1 segment and digit being on.

for (anode = 0; anode <4; anode = anode +1){
  for (segment = 0; segment<8; segment = segment+1){
  digitalWrite (anodePinArray[anode], HIGH); // turn on anode
   digitalWrite (segmentPinArray[segment], dataArray[anode][segment]); // turn segment on/off per value in dataArray - this line might need a little tweak

The 2nd multiplexing method is simillar, but can be 8 times faster because you would either write out a whole digit’s worth of data at one time using a PORT write if you have all the segments on one port, or transfer the segment data into a shift register.
Because you could turn on all segments at once, you would either have to limit the total anode current, or use a transistor to allow more anode current to flow into the segments - perhaps as much as 20ma/segment, so 140mA of cathode supply.

The loop within a loop concept is the same, only the segments become

digitalWrite (latchPin, LOW)
SPI.transfer(dataArray[segment]);  // sends 8 bits into shift register reeeeeally fast
digitalWrite (latchPin, HIGH); // data is latched into output register

and you can speed it up even more by using direct port manipulation in place of the digital writes, for example:

PORTD = PORTD & B10111111; // Bit6 goes low, rest unchanged
SPI.transfer(dataArray[segment]);  // sends 8 bits into shift register reeeeeally fast
PORTD = PORTD | B01000000;  // Bit6 goes high, rest unchanged
  1. set up a display buffer;
  2. write a display routine that turns on one digit to show one byte in the buffer;
  3. write another routine that rotates through the display buffer with the routine in 2)
  4. use a timer interrupt to call the routine in 3.
  5. done.

The advantage is that all your code has to do is to update the display buffer. The actual work surrounding displaying is done in the background by the timer interrupt.