Flickering 3 digit 7-segment display

Hello folks!
I am new to arduino /coding etc. I am trying to implement a counter from 0 to 999 with 1 second delay and represent it using 3 7-seven segment displays. I used the multiplexing method to connect my display to Arduino Uno board and it is working great...BUT! it is flickering( or however you call it guys) :~ . For a strange reason (for me at least) it is increments well but the printing to the 7-seg display is not like 000 > 001> 002 , instead i get 1>0>0 3>0>0 7>0>0 ( the ">" sign means the change of the display) . Can u please explain to me where is the problem in my code ( i think is something to do with the timing e.g too many instructions) and suggest a suitable way to reduce the flickering
Hardware : pins 1,2,3,4,5,6,7 are the segments
pins 8,9,10 are the digit selection
segments are common cathode(datasheet http://www.bitsbox.co.uk/data/optos/03cc.pdf )
Software:

void Display4(int value){
  static char digit=0;
  char digval[2];
  bin2bcd(value,digval);
  Display1(digval[digit],digit);
  if(++digit >= 3)
    digit=0;
     
}  

void bin2bcd (int valu, char* bcd){
  bcd[3]= valu/1000u;// for '1'
  bcd[2]= (valu/100)%10u;//for '10'
  bcd[1]= (valu/10u)%10u; //for '100'
  bcd[0]= valu%10u;//for '1000'
}

void Display1(char digval, char digit){
  digitsel(digval);//sents the number
  switch (digit){
  case 0: 
    digitalWrite(10, HIGH);
    digitalWrite(9, LOW);
   digitalWrite(8, LOW);
    break;
  case 1: 
    digitalWrite(9, HIGH);
   digitalWrite(8, LOW);
    digitalWrite(10, LOW);
    break;
  case 2: 
    digitalWrite(8, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    break;
  }
  
}


void digitsel( byte digit )
{
  switch (digit){
  case 0:
  digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(6, LOW);
  break;

  case 1:
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(1, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  break;

  case 2:
  digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(7, LOW);
  digitalWrite(3, LOW);
  break;

  case 3:
  digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  digitalWrite(7, LOW);
  break;

  case 4:
    digitalWrite(2, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(1, LOW);
  digitalWrite(5, LOW);
  digitalWrite(4, LOW);
  break;

  case 5:
   digitalWrite(1, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(5, LOW);
    break;

  case 6:
    digitalWrite(7, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(1, HIGH);
  digitalWrite(2, LOW);
    break;

  case 7:
   digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
    break;

  case 8:
   digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
    break;

  case 9:
  digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
    break;
  default:  
  break; 
  }
}
float t=0;
void setup()
{  
  //Serial.begin(9600);
  for (int i = 1; i < 11; i++) // set pins 0-7 as outputs
  {
    pinMode(i, OUTPUT);
   // Serial.println(i);
   
  }
  
}

void loop()
{ 
  Display4(t);
  t++;
  if(t >= 999)
  {t=0;}
  delay(1000);
  
}

P.S 1 :Please don't suggest to use shift registers I want to learn this way
P.S 2 :I did search for similar threats but nothing ...
P.S 3: I am new to everything above so please be nice :grin:

How many 7-segment units do you have wired up? From the code I see, it looks like it is working correctly. The code is only displaying a digit on one 7-segment unit.

Hi thanks for the reply! :slight_smile:
I have wired up 3 units ( I made the code for 4 units though) .
Yes the code is working like this one digit at a time...
If I change the delay inside the void loop() from 1000 to 10 it is not flickering but it is counting too fast. So my question is why the delay inside the void loop affects the hole program? :~
Thanks again!

I missed the part of the code that selects a digit. Sounds like you are using a multiplexed display. This means the digit is only on, while it is selected. This is confirmed by you changing the delay. The digits appear to be "on" because your eyes are slower than the lights are flashing.

You need to rewrite your code/loop so that it is constantly updating the display, with the same value, while incrementing the variable separately.

This is a good use for millis().