7 segment 3 digit display third digit never lit

Hi Every one ,

This is my first post regarding issue with my code, for counter 0, 100.
two dogit working fine but third digit doesn't lit. Is there any body can help me.

Kind Regards
Here is my code

//Prepare binary array for all 7 segment to turn on 7 segment at position of a,b,c,d,e,f,g
char digit[10] = { 0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111 };

int digit1 = 12, digit2 = 3, digit3 = 2;  // initialize individual digit to controll each segment
char a = 0, b = 0, c = 0;
void setup() {
  for (int i = 2; i < 13; i++) 
    pinMode(i, OUTPUT);  // declare 0-9 th pin as output
  
    digitalWrite(digit1, LOW);
    digitalWrite(digit2, LOW);
    digitalWrite(digit3, LOW);
   
}
void loop() {
  
  a++;
  if (a > 9){ a = 0;b++;}
  if (b > 9) { b = 0; c++;}
  if (c > 9)  c = 0;

  for(int k=0; k<10; k++){
  digitalWrite(digit1, LOW);
  digitalWrite(digit2, HIGH);
  digitalWrite(digit3, HIGH);
  senddata(a);
  delay(5);
  digitalWrite(digit1, HIGH);
  digitalWrite(digit2, LOW);
  digitalWrite(digit3, HIGH);
  senddata(b);
  delay(5);
  digitalWrite(digit1, HIGH);
  digitalWrite(digit2, HIGH);
  digitalWrite(digit3, LOW);
  senddata(c);
  delay(5);
  }
}

void senddata(unsigned char y) {
  unsigned char  t;
  t= digit[y];
  boolean x;
  for(int j=0; j<8; j++)
  {
    x= bitRead(t,j);
    digitalWrite(j+4,x);
  }
}

pic

Exchange pins 2 and 12 or 3 and 12, run your sketch and describe the results. I assume the 3x7seg has an external power supply (24 segs x 15mA/seg = 360mA).

It's a multiplexed display. You can't light all 24 segments simultaneously.

Thank you so much for your reply, I exchange the wire, now third one lit, but second one never lit, I think there is no enough power, I am going to add transister on digit pins and power it from external power supply.

It doesn't matter. It's only a simulation. Simulators don't normally accurately model the effects of inadequate power supplies.

Thank you very much I will try to use sevseg library.

//Prepare binary array for all 7 segment to turn on 7 segment at position of a,b,c,d,e,f,g
const byte digit[10] = { 0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111 };
const byte digit1 = 12, digit2 = 3, digit3 = 2;  // initialize individual digit to controll each segment
byte a = 0, b = 0, c = 0;
#define makePinHIGH(b) (b)<13?(b)<8?PORTD|=1<<(b):PORTB|=1<<(b-8):(PORTC|=(1<<(b-13)))
#define makePinLOW(b) (b)<13?(b)<8?PORTD&=~(1<<(b)):PORTB&=~(1<<(b-8)):PORTC&=~(1<<(b-13))

void setup() {
  for (int i = 2; i < 13; i++)pinMode(i, OUTPUT);  // declare 0-9 th pin as output
}

void loop() {
  static byte Val = 0;
  a = Val % 10;
  b = (Val / 10) % 10;
  c = Val / 100;
  Val++;
  if (Val == 1000)Val = 0;
  for (int k = 0; k < 10; k++) {
    makePinLOW(digit1);
    makePinHIGH(digit2);
    makePinHIGH(digit3);
    senddata(a);
    delay(5);
    makePinHIGH(digit1);
    makePinLOW(digit2);
    makePinHIGH(digit3);
    senddata(b);
    delay(5);
    makePinHIGH(digit1);
    makePinHIGH(digit2);
    makePinLOW(digit3);
    senddata(c);
    delay(5);
  }
}

void senddata(byte y) {
  for (int j = 0; j < 8; j++)    bitRead(digit[y], j) ? makePinHIGH(j + 4) : makePinLOW(j + 4);
}

The original sketch works fine in real life.