5 digit 7-segment display controller (arduino mega)

Hi, so I have a 5-digit 7-segment common anode display connected to my arduino mega. I have a 220 ohm resistor connected to each segment pin as a current-limiting resistor. I see other threads with people using transistors to control the digit pins. Is this required? I have some code set up for my 5-digit display (without using any library) and have gotten the numbers to light up (no decimal point yet), but I haven't used any transistors to control the digits, so I'm wondering if my method for driving the display is wrong. The display lights up nice and bright, but when I input a number like "18181" into the serial monitor, you can see dim outlines for the segments for number 8, overlapping in the places where the 1 is.

#define aPin 22    //               A
#define bPin 23    //            ________
#define cPin 24    //          |          |
#define dPin 25    //       F  |          |  B
#define ePin 26    //          |          |
#define fPin 27     //         | ________ |
#define gPin 28   //                G
#define DP   29    //          |          |
#define D1    8     //         |          |
#define D2    9     //      E  |          |  C 
#define D3   10    //          | ________ |
#define D4   11    //               D
#define D5   12           
unsigned long num;                  
unsigned long dig1 = 0;
unsigned long dig2 = 0;
unsigned long dig3 = 0;
unsigned long dig4 = 0;
unsigned long dig5 = 0;
unsigned long DTime = 2;


void setup()
{
  pinMode(aPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  pinMode(cPin, OUTPUT);
  pinMode(dPin, OUTPUT);
  pinMode(ePin, OUTPUT); 
  pinMode(fPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(DP,OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(D4, OUTPUT);
  pinMode(D5, OUTPUT);
  Serial.begin(9600);
  Serial.setTimeout(30);
}
void loop()
{
  digitalWrite( D1, LOW);
  digitalWrite( D2, LOW);
  digitalWrite( D3, LOW);
  digitalWrite( D4, LOW);
  digitalWrite( D5, LOW);
 
if (Serial.available() > 0)
{
  num = Serial.parseInt();
  Serial.print("Displaying: "); Serial.println(num);
  dig1 = num / 10000;
  num = num - (dig1 * 10000);
  dig2 = num / 1000;
  num = num - (dig2 * 1000);
  dig3 = num / 100;
  num = num - (dig3 * 100);
  dig4 = num / 10;
  num = num - (dig4 * 10);
  dig5 = num;
}

  digitalWrite( D1, HIGH);    //digit 1
  pickNumber(dig1);
  delay(DTime);
  digitalWrite( D1, LOW);
  

  digitalWrite( D2, HIGH);    //digit 2
  pickNumber(dig2);
  delay(DTime);
  digitalWrite( D2, LOW);


  digitalWrite( D3, HIGH);    //digit 3
  pickNumber(dig3);
  delay(DTime);
  digitalWrite( D3, LOW);


  digitalWrite( D4, HIGH);   //digit 4
  pickNumber(dig4);
  delay(DTime);
  digitalWrite( D4, LOW);


  digitalWrite( D5, HIGH);   //digit 5
  pickNumber(dig5);
  delay(DTime);
  digitalWrite( D5, LOW);


}
 
void pickNumber(int x){
   switch(x){
     case 1: one(); break;
     case 2: two(); break;
     case 3: three(); break;
     case 4: four(); break;
     case 5: five(); break;
     case 6: six(); break;
     case 7: seven(); break;
     case 8: eight(); break;
     case 9: nine(); break;
     default: zero(); break;
   }
}

void clearLEDs()
{  
  digitalWrite(  2, LOW); // A
  digitalWrite(  3, LOW); // B
  digitalWrite(  4, LOW); // C
  digitalWrite(  5, LOW); // D
  digitalWrite(  6, LOW); // E
  digitalWrite(  7, LOW); // F
  digitalWrite(  8, LOW); // G
}

void one() //B, C set
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void two() //A, B, D, E, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, LOW);
}

void three() //A, B, C, D, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, LOW);
}

void four() //B, C, F, G set
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void five() //A, C, D, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void six() //A, C, D, E, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void seven() //A, B, C set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void eight() //A, B, C, D, E, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void nine() //A, B, C, D, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void zero() //A, B, C, D, E, F set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, HIGH);
}

trrychau:
I see other threads with people using transistors to control the digit pins. Is this required?

With 220R resistors? Yes. Otherwise you will overload the Arduino pins connected to the segment commons. The max for an individual pin is 40mA, and even that should used on exceptionally rare occasions. 25 to 30mA for continuous use is a better max.

Paul

PaulRB:
With 220R resistors? Yes. Otherwise you will overload the Arduino pins connected to the segment commons.

Okay, I don't want to overload my precious Arduino pins.

So if I get 5 transistors (one for each digit pin) and connect the emitters to 5v, collectors to common anode pin, and bases into the Arduino board, and control the separate digit pins that way, it should be enough to protect the Arduino pins from getting damaged right?

Also, some people are using shift registers, are these required to multiplex the display or can I just do the multiplexing with code?

Have a look at this and let me know if you have any questions.

PaulRB:
Have a look at this and let me know if you have any questions.

Hey Paul, I have a couple questions after looking at your link:

I apologize for any stupid questions, but I will have a much better idea of how multiplexed displays will work if you can answer them!

  1. You used the seven segment library, which is intended to use with only 4 digits displays. Could I use the same library and tweak it to work for a 5 digit display?

  2. Would 5 PNP transistors work to control 5 digits like you did with your NPN transistors? Which ones do you suggest that I use?

  3. Are you using the +5V supply from the Arduino board to provide the VCC for the transistors?

  4. How do I code the Arduino to get the display to read and display floating point numbers (decimal point segment)?

  5. What's the capacitors C1 and C2 used for?

trrychau:

  1. You used the seven segment library

No, I didn't. Can I suggest you take another look?

trrychau:
2. Would 5 PNP transistors work to control 5 digits like you did with your NPN transistors? Which ones do you suggest that I use?

Yes, you could use bc327 for example. You would then need resistors between the pnp bases and the Arduino pins, 4K7 would be suitable. A minor code change would also be needed.

trrychau:
3. Are you using the +5V supply from the Arduino board to provide the VCC for the transistors?

Yes, the display will only draw around 130mA with 330R series resistors, 270mA with 150R resistors, so this won't overload the USB power or the Arduino's regulator.

trrychau:
4. How do I code the Arduino to get the display to read and display floating point numbers (decimal point segment)?

You just set the bit corresponding to the decimal point after you have looked up the pattern for the required digit.

trrychau:
5. What's the capacitors C1 and C2 used for?

They are to help smooth the spikes in current when the transistors switch on and off, and to absorb any high frequency spikes caused by the switching. You may get away with not using them, but its a good habit to be in and could prevent problems, that would be difficult to diagnose, in other circuits you build in the future.

trrychau:
I haven't used any transistors to control the digits, so I'm wondering if my method for driving the display is wrong. The display lights up nice and bright, but when I input a number like "18181" into the serial monitor, you can see dim outlines for the segments for number 8, overlapping in the places where the 1 is.

Lets hope these "dim outlines" are not because you have already damaged the Arduino pins by overloading them. With 220R series resistors, the pins connected to the common anodes would be sourcing 160mA, which is 4 times the maximum. This may have damaged them and now they won't switch off properly, resulting in some current leaking when they are supposed to be LOW.

Hopefully I didn't damage the pins! Another question: for the transistors, how come it's better to use them to control the digit pins as opposed to the segment pins?

Because 7 or 8 times more current flows through the digit pins, compared to the segment pins.

trrychau:
Also, some people are using shift registers, are these required to multiplex the display or can I just do the multiplexing with code?

Shift registers can be used to avoid multiplexing.

Basically, what shift registers do is they effectively give your Arduino a lot of extra output pins. This way (if you have enough shift registers), each segment of each digit can have its own output pin.

Since you seem to want a very bright display, I would recommend you use shift registers. But then again, I'm not really a hardware guy, so maybe this isn't the best suggestion for you.

What do the other people here have to say about this?

You want bright, use a TPIC6B595 shift register per digit with common anode displays to sink current thru the LEDs.
This board I offer supports up to 12 digits, designed for digits made from LED strips, but can do individual LEDs as well.
http://www.crossroadsfencing.com/BobuinoRev17/

Thanks for the suggestion CrossRoads. I should probably mention I'm using this:

http://www.ebay.com/itm/141058406338

I don't know if I'll end up using a shift register. I just bought some transistors though, so I'll be trying to hook up the circuit the way Paul has it set up. They're NTE159 PNP transistors so hopefully they work. I'll give updates.

-Terry

Hmm.. the eBay page does not seem to specify the forward voltage or the max current for those displays, which is quite poor of the vendor. But you can measure the forward voltage and its fairly safe to assume a 20mA max current. You do have a DMM?

As for those transistors, they might be ok, although the current gain is rather low (they are intended as audio amplifiers, rather than for switching).

How did you choose these particular components?

I just went to the JK Electronics store by my house, and they didn't have BC557 transistors, so I just asked for some random PNP's.

Anyways, I hooked it up with the transistors (and 330R resistors), and I fixed the issue with the dim outline of the segments lighting up when they're not supposed to, by calling my clearLEDs() function after drawing each digit, but this drastically reduces the brightness of the display...

And if I remove the clearLEDs() the brightness comes back up but so does the dim segment outlines :frowning:

Maybe there's a coding issue?

#define aPin 32    //               A
#define bPin 33    //            ________
#define cPin 34    //          |          |
#define dPin 35    //       F  |          |  B
#define ePin 36    //          |          |
#define fPin 37     //         | ________ |
#define gPin 38   //                G
//#define DP   29    //          |          |
#define D1    8     //         |          |
#define D2    9     //      E  |          |  C 
#define D3   10    //          | ________ |
#define D4   11    //               D
#define D5   12           
unsigned long num;                  
unsigned long dig1 = 0;
unsigned long dig2 = 0;
unsigned long dig3 = 0;
unsigned long dig4 = 0;
unsigned long dig5 = 0;
unsigned long DTime = 3;

void setup()
{
  pinMode(aPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  pinMode(cPin, OUTPUT);
  pinMode(dPin, OUTPUT);
  pinMode(ePin, OUTPUT); 
  pinMode(fPin, OUTPUT);
  pinMode(gPin, OUTPUT);
//pinMode(DP,OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(D4, OUTPUT);
  pinMode(D5, OUTPUT);

  digitalWrite( D1, HIGH);
  digitalWrite( D2, HIGH);
  digitalWrite( D3, HIGH);
  digitalWrite( D4, HIGH);  
  digitalWrite( D5, HIGH);
  
  Serial.begin(9600);
  Serial.setTimeout(30);
}
void loop()
{
 
if (Serial.available() > 0)
{
  num = Serial.parseInt();
  Serial.print("Displaying: "); Serial.println(num);
  dig1 = num / 10000;
  num = num - (dig1 * 10000);
  dig2 = num / 1000;
  num = num - (dig2 * 1000);
  dig3 = num / 100;
  num = num - (dig3 * 100);
  dig4 = num / 10;
  num = num - (dig4 * 10);
  dig5 = num;
}
  digitalWrite( D1, LOW);    //digit 1
  pickNumber(dig1);
  clearLEDs();
  delay(DTime);
  digitalWrite( D1, HIGH);
  
  digitalWrite( D2, LOW);    //digit 2
  pickNumber(dig2);
  clearLEDs();
  delay(DTime);
  digitalWrite( D2, HIGH);
  
  digitalWrite( D3, LOW);    //digit 3
  pickNumber(dig3);
  clearLEDs();
  delay(DTime);
  digitalWrite( D3, HIGH);

  digitalWrite( D4, LOW);   //digit 4
  pickNumber(dig4);
  clearLEDs();
  delay(DTime);
  digitalWrite( D4, HIGH);
  
  digitalWrite( D5, LOW);   //digit 5
  pickNumber(dig5);
  clearLEDs();
  delay(DTime);
  digitalWrite( D5, HIGH);
}
 
void pickNumber(int x){
   switch(x){
     case 1: one(); break;
     case 2: two(); break;
     case 3: three(); break;
     case 4: four(); break;
     case 5: five(); break;
     case 6: six(); break;
     case 7: seven(); break;
     case 8: eight(); break;
     case 9: nine(); break;
     default: zero(); break;
   }
}

void clearLEDs()
{  
  digitalWrite( aPin, HIGH); // A
  digitalWrite( bPin, HIGH); // B
  digitalWrite( cPin, HIGH); // C
  digitalWrite( dPin, HIGH); // D
  digitalWrite( ePin, HIGH); // E
  digitalWrite( fPin, HIGH); // F
  digitalWrite( gPin, HIGH); // G
}

void one() //B, C set
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void two() //A, B, D, E, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, LOW);
}

void three() //A, B, C, D, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, LOW);
}

void four() //B, C, F, G set
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void five() //A, C, D, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void six() //A, C, D, E, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void seven() //A, B, C set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void eight() //A, B, C, D, E, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void nine() //A, B, C, D, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void zero() //A, B, C, D, E, F set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, HIGH);
}

PaulRB:
Hmm.. the eBay page does not seem to specify the forward voltage or the max current for those displays, which is quite poor of the vendor. But you can measure the forward voltage and its fairly safe to assume a 20mA max current. You do have a DMM?

As for those transistors, they might be ok, although the current gain is rather low (they are intended as audio amplifiers, rather than for switching).

How did you choose these particular components?

I have a DMM here with me, where do I measure the forward voltage and current? My transistor knowledge is pretty rusty

trrychau:
I have a DMM here with me, where do I measure the forward voltage and current? My transistor knowledge is pretty rusty

I'm talking about the forward voltage (Vf) and max current (Imax) of the led segments in the displays.

Green leds are likely to have a Vf of around 2.0 to 3.5V. If we assume the lowest likely value, then the series resistor should be

(5.0 - 2.0) / 0.010 = 300R

assuming 5.0V supply and a test current of 10mA. So start with a 330R resistor. Put this in series with one segment, across the 5V and GND pins of the Arduino. Then set your DMM to the 20V DC scale and measure the voltage drop across the display. That's your Vf. If I'm right about the likely range, you can then try a 150R resistor. The voltage drop across the display should not change much, perhaps 0.1V or so. Also measure the current flowing through the segment & resistor using the 200mA range on the DMM.

There's only one way of measuring the Imax that I can think of, which involves increasing the current until the display burns out! But 20mA is usually a good guess, that's the limit for most displays I've seen the data sheets for. That's the max continuous current. You can go over that to a degree (e.g. double) of you are multiplexing with a 1:5 ratio as you are intending to do.

I'll have a look at your sketch later.

Alright well I edited my code and it seems like it works now. The changes I made:

  1. Clearing the segments after drawing the number for each digit removed the overlapping problem for me (however it dimmed the brightness of the whole display, which I fixed in #2)

  2. I removed the delay between setting each digit HIGH to LOW. The brightness is now back and looks great again. I'm not sure why I even needed to have a delay here anyways (can anyone explain why this is even needed because I know some people do this).

Revised code:

#define aPin 32    //               A
#define bPin 33    //            ________
#define cPin 34    //          |          |
#define dPin 35    //       F  |          |  B
#define ePin 36    //          |          |
#define fPin 37     //         | ________ |
#define gPin 38   //                G
//#define DP   29    //          |          |
#define D1    8     //         |          |
#define D2    9     //      E  |          |  C 
#define D3   10    //          | ________ |
#define D4   11    //               D
#define D5   12           
unsigned long num;                  
unsigned long dig1 = 0;
unsigned long dig2 = 0;
unsigned long dig3 = 0;
unsigned long dig4 = 0;
unsigned long dig5 = 0;
unsigned long DTime = 1;

void setup()
{
  pinMode(aPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  pinMode(cPin, OUTPUT);
  pinMode(dPin, OUTPUT);
  pinMode(ePin, OUTPUT); 
  pinMode(fPin, OUTPUT);
  pinMode(gPin, OUTPUT);
//pinMode(DP,OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(D4, OUTPUT);
  pinMode(D5, OUTPUT);

  digitalWrite( D1, HIGH);
  digitalWrite( D2, HIGH);
  digitalWrite( D3, HIGH);
  digitalWrite( D4, HIGH);  
  digitalWrite( D5, HIGH);
  
  Serial.begin(9600);
  Serial.setTimeout(30);
}

void loop()
{
 
if (Serial.available() > 0)
{
  num = Serial.parseInt();
  Serial.print("Displaying: "); Serial.println(num);
  dig1 = num / 10000;
  num = num - (dig1 * 10000);
  dig2 = num / 1000;
  num = num - (dig2 * 1000);
  dig3 = num / 100;
  num = num - (dig3 * 100);
  dig4 = num / 10;
  num = num - (dig4 * 10);
  dig5 = num;
}
  digitalWrite( D1, LOW);    //digit 1
  pickNumber(dig1);
  clearLEDs();
  digitalWrite( D1, HIGH);
//delay(DTime);
  
  digitalWrite( D2, LOW);    //digit 2
  pickNumber(dig2);
  clearLEDs();
  digitalWrite( D2, HIGH);
//delay(DTime);
  
  
  digitalWrite( D3, LOW);    //digit 3
  pickNumber(dig3);
  clearLEDs();
  digitalWrite( D3, HIGH);
//delay(DTime);

  digitalWrite( D4, LOW);   //digit 4
  pickNumber(dig4);
  clearLEDs();
  digitalWrite( D4, HIGH);
//delay(DTime);
  
  digitalWrite( D5, LOW);   //digit 5
  pickNumber(dig5);
  clearLEDs();
  digitalWrite( D5, HIGH);
//delay(DTime);
}
 
void pickNumber(int x){
   switch(x){
     case 1: one(); break;
     case 2: two(); break;
     case 3: three(); break;
     case 4: four(); break;
     case 5: five(); break;
     case 6: six(); break;
     case 7: seven(); break;
     case 8: eight(); break;
     case 9: nine(); break;
     default: zero(); break;
   }
}

void clearLEDs()
{  
  digitalWrite( aPin, HIGH); // A
  digitalWrite( bPin, HIGH); // B
  digitalWrite( cPin, HIGH); // C
  digitalWrite( dPin, HIGH); // D
  digitalWrite( ePin, HIGH); // E
  digitalWrite( fPin, HIGH); // F
  digitalWrite( gPin, HIGH); // G
}

void one() //B, C set
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void two() //A, B, D, E, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, HIGH);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, LOW);
}

void three() //A, B, C, D, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, LOW);
}

void four() //B, C, F, G set
{
  digitalWrite( aPin, HIGH);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void five() //A, C, D, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void six() //A, C, D, E, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, HIGH);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void seven() //A, B, C set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, HIGH);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, HIGH);
  digitalWrite( gPin, HIGH);
}

void eight() //A, B, C, D, E, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void nine() //A, B, C, D, F, G set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, HIGH);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, LOW);
}

void zero() //A, B, C, D, E, F set
{
  digitalWrite( aPin, LOW);
  digitalWrite( bPin, LOW);
  digitalWrite( cPin, LOW);
  digitalWrite( dPin, LOW);
  digitalWrite( ePin, LOW);
  digitalWrite( fPin, LOW);
  digitalWrite( gPin, HIGH);
}

trrychau:
can anyone explain why this is even needed because I know some people do this

Without the delay between digits, the Arduino is multiplexing much faster than is needed to avoid flickering. Setting up the segments between digits takes a little time. Not much time, but some. The faster the multiplexing, the larger % of the time this setting up takes, so the average brightness goes down. With no delay at all between digits, the brightness could be as little as 50% of the potential maximum. With a delay between digits that is just short enough to avoid flickering, the brightness could be 90%+.

Secondly, if the Arduino is doing nothing else except the multiplexing, then multiplexing unnecessarily fast doesn't matter too much (except for the brightness issue). But if you want the Arduino to perform other tasks at the same time, you need to make the multiplexing just fast enough to avoid flicker, without using too much % of the cpu time doing it. You also have to avoid using the delay() function, because that deliberately wastes cpu time. Instead,time the switching of digits using the millis() function.