4 Digit led display - How to have 4 different numbers?

I’ve ordered a 4 digit led display from ebay because it was cheap and looked cool :grin: haha… But I’m a bit clueless about how to use it. I’m able to show numbers, but the 4 digits show the same number/symbol…

I have hooked the digit led display to my arduino (it’s a common anode display).

I just seem to be unable to have 4 different numbers, as all 4 numbers are always the same.

here is my code
– Controlpin is the positive pin from the arduino, actually doesn’t need any control but it’s just in order to give power to the LED.
the pins of my display are like this
| | | | | | |

| | | | | | |

I’ve called them
A B C D E F

G H I J K L

in order to make it easier for myself and defined them in variables (corresponding pin).

char controlPin = 13;
char a = 12;
char b = 11;
char e = 10;
char g = 9;
char h = 8;
//char i = 7;
char j = 7;
char k = 6;

void setup()
{
  int i = 0;
  pinMode(controlPin, OUTPUT);
  digitalWrite(controlPin, HIGH);
  for(i = 12; i >= 6; i--)
    pinMode(i, OUTPUT);
  for(i = 12; i >= 6; i--)
    digitalWrite(i,  LOW);   //low is ground -- current can flow through! common anode
  delay(500);
  for(i = 12; i >= 6; i--)
    digitalWrite(i, HIGH);
}

void loop()
{
  randomShow(50);
  randomShow(70);
  countUp();
  randomShow(50);
  randomShow(70);
  countDown();
  randomShow(50);
  randomShow(70);  
  randomShow(50);
  countUp();
  countDown();
  //randomShowInvert(50);

}

void countUp()
{
 showZero();
 delay(1000);
 showOne();
 delay(1000);
 showTwo();
 delay(1000);
 showThree();
 delay(1000);
 showFour();
 delay(1000);
 showFive();
 delay(1000);
 showSix();
 delay(1000);
 showSeven();
 delay(1000);
 showEight();
 delay(1000);
 showNine();
 delay(1000);
}

void countDown()
{
  showNine();
  delay(1000);
  showEight();
  delay(1000);
  showSeven();
  delay(1000);
  showSix();
  delay(1000);
  showFive();
  delay(1000);
  showFour();
  delay(1000);
  showThree();
  delay(1000);
  showTwo();
  delay(1000);
  showOne();
  delay(1000);
  showZero();
  delay(1000);
}

void randomShow(int time)
{
  int i = 0;
  for(i = 12; i >= 6; i--)
  {
    digitalWrite(i,  LOW);  //All off
    if(i < 10)
      digitalWrite(i+2, LOW);
    if(i > 8)
      digitalWrite(i-2, LOW);
    delay(time);
    digitalWrite(i, HIGH);
    if(i < 10)
      digitalWrite(i+2, HIGH);
    if(i > 8)
      digitalWrite(i-2, HIGH);
    delay(time);
  }
}

void realRandomShow(int time)
{
  int i = 0, rander;
  for(i = 12; i >= 6; i--)
  {
    digitalWrite(i,  LOW);  //All off
    //Get a rand() that does not exceed limits
    rander = 0;
    rander = (rand() % 7) + 6;
    while(rander == i)
      rander = (rand() % 7) + 6;
 
    if(i < 10)
     // digitalWrite(i+2, LOW);
      digitalWrite(i+(rander %2), LOW);
    if(i > 8)
//      digitalWrite(i-2, LOW);
      digitalWrite(i-(rander % 2), LOW);
    delay(time);
    digitalWrite(i, HIGH);
    if(i < 10)
     // digitalWrite(i+2, LOW);
      digitalWrite(i+(rander %2), HIGH);
    if(i > 8)
//      digitalWrite(i-2, LOW);
      digitalWrite(i-(rander % 2), HIGH);
    delay(time);
  }
  
/*  for(i = 12; i >= 6; i--)
  {
    digitalWrite(i,  LOW);  
    delay(time);
  }*/
}

void randomShowInvert(int time)
{
  int i = 0;
  for(i = 0; i <= 12; i++)
  {
    digitalWrite(i,  HIGH);  //All off
    delay(time);
  }
  
  for(i = 0; i <= 12; i++)
  {
    digitalWrite(i,  LOW);  
    delay(time);
  }
}

void showZero()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // ABEJHG
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(e, LOW);
  digitalWrite(j, LOW);
  digitalWrite(h, LOW);
  digitalWrite(g, LOW);
}

void showOne()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // E, J on
  digitalWrite(e, LOW);
  digitalWrite(j, LOW);
}

void showTwo()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // A, E, K, G, H
  digitalWrite(a, LOW);
  digitalWrite(e, LOW);
  digitalWrite(k, LOW);
  digitalWrite(g, LOW);
  digitalWrite(h, LOW);
}

void showThree()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // A, E, K, J, H
  digitalWrite(a, LOW);
  digitalWrite(e, LOW);
  digitalWrite(k, LOW);
  digitalWrite(j, LOW);
  digitalWrite(h, LOW);
}

void showFour()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // BKEJ
  digitalWrite(b, LOW);
  digitalWrite(k, LOW);
  digitalWrite(e, LOW);
  digitalWrite(j, LOW);
}

void showFive()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // ABKJH
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(k, LOW);
  digitalWrite(j, LOW);
  digitalWrite(h, LOW);
}


void showSix()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // A, E, K, J, H, H
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(k, LOW);
  digitalWrite(j, LOW);
  digitalWrite(h, LOW);
  digitalWrite(g, LOW);
}

void showSeven()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // A, E,  J
  digitalWrite(a, LOW);
  digitalWrite(e, LOW);
  digitalWrite(j, LOW);
}

void showEight()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // A,B  E, K, J, H G
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(e, LOW);
  digitalWrite(k, LOW);
  digitalWrite(j, LOW);
  digitalWrite(h, LOW);
  digitalWrite(g, LOW);
}

void showNine()
{
  //Turn all others off
  int i = 0;
  for(i = 0; i <= 12; i++)
    digitalWrite(i,  HIGH);  //All off
    
  // A,B  E, K, J, H 
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(e, LOW);
  digitalWrite(k, LOW);
  digitalWrite(j, LOW);
  digitalWrite(h, LOW);
}

All of above works, but all 4 digits do the same… I don’t see how I would make other digits do other things since there are only 12 pins? Hmm :/…

Thanks for the help!

What happens if you light one digit at a time? Hint: google multiplexed display.

I thought it had to do with multiplexing, but I wasn't sure :P. Not sure what it is yet though.

Yeah well one digit at a time -- okay I get my number, but there's only 1 digit :P, I'm talking about different numbers on multiple digits.

Thanks for the help.

goes googling

If you display single digits fast enough, your eye sees them as separate digits.

I made an alarm clock with a 4 digit display:

http://www.gammon.com.au/forum/?id=11165

Basically you show each digit briefly (like 2 milliseconds), and move onto the next one.