7-SEGMENT COUNTER 0-99 with 74HC595

So far I made this code.
Am I going in the right direction?

I dont know how should I modify function showNumber, could you show me how to do it?

const byte  latchPin = 5;  // Pin connected to Pin 5 of 74HC595 (Latch)
const byte dataPin  = 6;   // Pin connected to Pin 6 of 74HC595 (Data)
const byte clockPin = 7;   // Pin connected to Pin 7 of 74HC595 (Clock)

const byte UpPinFirst = 12;     // pushbutton connected to pin 12 for increment by 1 (first counter)
const byte DownPinFirst = 13;   // pushbutton connected to pin 13 for decrement by 1 (first counter)


const byte UpPinSecond = A1;     // pushbutton connected to pin A1 for increment by 1 (second
counter)
const byte DownPinSecond = A2;   // pushbutton connected to pin A2 for decrement by 1 (second counter)


const byte DigitFirst1 = 8;     // transistor for ones digit of  connected to pin 8(first counter)
const byte DigitFirst2 = 9;     // transistor for tens digit connected to pin 9 (first counter)
const byte DigitSecond1 = 2;     // transistor for ones digit of  connected to pin 2(second counter)
const byte DigitSecond2 = 3;     // transistor for tens digit connected to pin 3 (second counter)

const byte reset = A0;
int res = 0;


int prevUpStateFirst = 0;
int prevDownStateFirst = 0;
int currUpStateFirst = 1;
int currDownStateFirst = 1;

int prevUpStateSecond = 0;
int prevDownStateSecond = 0;
int currUpStateSecond = 1;
int currDownStateSecond = 1;

int counterFirst = 0;           // initialise first counter as zero
int counterSecond = 0;           // initialise second counter as zero

byte numberOfDigits = 2;

const byte numbers[10] =   // Describe each digit in terms of display segments  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
{
  B11111100, //0
  B01100000, //1
  B11011010, //2
  B11110010, //3
  B01100110, //4
  B10110110, //5
  B10111110, //6
  B11100000, //7
  B11111110, //8
  B11110110, //9
};

void setup()
{
  pinMode(latchPin, OUTPUT);   // set shift registers pins to output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  pinMode(UpPinFirst, INPUT);     
  pinMode(DownPinFirst, INPUT);    
  pinMode(DigitFirst1, OUTPUT);
  pinMode(DigitFirst2, OUTPUT);

  pinMode(UpPinSecond, INPUT);      
  pinMode(DownPinSecond, INPUT);          
  pinMode(DigitSecond1, OUTPUT);
  pinMode(DigitSecond2, OUTPUT);

   pinMode(reset, INPUT);
  
}

void loop()
{
  //counter part
  //first counter
  
  currUpStateFirst = digitalRead(UpPinFirst);
  if (prevUpStateFirst != currUpStateFirst)           // has the state changed from HIGH to LOW or vice versa 
  {                                         
    prevUpStateFirst = !prevUpStateFirst;             //invert
    if (currUpStateFirst == HIGH && counterFirst <= 99)  // If the button was pressed AND not reached 99
        counterFirst++;                                     // increment the counter by one

    if(counterFirst > 99) counterFirst = 0;                 //if counter is greater than 99, set it to 0

  }

  currDownStateFirst = digitalRead(DownPinFirst);
  if (prevDownStateFirst != currDownStateFirst)        // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevDownStateFirst = currDownStateFirst;
    if (currDownStateFirst == HIGH && counterFirst >= 0)  // If the button was pressed AND not reached 0
        counterFirst--;                                      // decrement the counter by one  
    if(counterFirst < 0) counterFirst = 99;                  // counting backward from 99 to 0

  }

  
//second counter

  currUpStateSecond = digitalRead(UpPinSecond);
  if (prevUpStateSecond != currUpStateSecond)           // has the state changed from HIGH to LOW or vice versa
  {                                         
    prevUpStateSecond = !prevUpStateSecond;             //invert
    if (currUpStateSecond == HIGH && counterSecond <= 99)  // If the button was pressed AND not reached 99
        counterSecond++;                                      // increment the counter by one

    if(counterSecond > 99) counterSecond = 0;                 //if counter is greater than 99, set it to 0

  }

  currDownStateSecond = digitalRead(DownPinSecond);
  if (prevDownStateSecond != currDownStateSecond)        // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevDownStateSecond = currDownStateSecond;
    if (currDownStateSecond == HIGH && counterSecond >= 0)  // If the button was pressed AND not reached 0
        counterSecond--;                                       // decrement the counter by one  
    if(counterSecond < 0) counterSecond = 99;                  // counting backward from 99 to 0

  }

  
  

  res = digitalRead(reset);      //if the reset button was pressed, set the counters to 0
  if(res == HIGH) 
  counterFirst = 0;
  counterSecond = 0;
  
  
  showNumber(counterFirst);           // display the current digit 
}

void showNumber(int number)
{
  // digits are : (Digit1 - pin 8) and  (Digit2 - pin 9)

  for(byte i = 0; i < numberOfDigits; i++)
  { 
    
    digitalWrite(DigitFirst1, LOW ) ;   // switch off Digit1(ones)
    digitalWrite(DigitFirst2, LOW ) ;   // switch off Digit2(tens)

    digitalWrite(latchPin, LOW);   // Set latchPin LOW while clocking bits in to the register

    shiftOut(dataPin, clockPin, LSBFIRST, numbers[number % 10]);
    number /= 10;

   digitalWrite(latchPin, HIGH);     //set latchPin to high to lock and send data

     digitalWrite(DigitFirst1, ( i == 0 ) ) ; // switch on/off Digit1   
  
     digitalWrite(DigitFirst2, ( i == 1 ) ) ; // switch on/off Digit2

     delay(5);
  }
}

This version of showNumber() should support 4 digits.

byte numberOfDigits = 4;  // was 2

...
...
...


void showNumber(int number)
{
  

  for(byte i = 0; i < numberOfDigits; i++)
  {
   
    digitalWrite(DigitFirst1, LOW ) ;   // switch off Digit1(ones)
    digitalWrite(DigitFirst2, LOW ) ;   // switch off Digit2(tens)
    digitalWrite(DigitSecond1, LOW ) ;   // switch off Digit3(hundreds)
    digitalWrite(DigitSecond2, LOW ) ;   // switch off Digit4(thousands)

    digitalWrite(latchPin, LOW);   // Set latchPin LOW while clocking bits in to the register

    shiftOut(dataPin, clockPin, LSBFIRST, numbers[number % 10]);
    number /= 10;

   digitalWrite(latchPin, HIGH);     //set latchPin to high to lock and send data

     digitalWrite(DigitFirst1, ( i == 0 ) ) ; // switch on/off Digit1   
 
     digitalWrite(DigitFirst2, ( i == 1 ) ) ; // switch on/off Digit2

     digitalWrite(DigitSecond1, ( i == 2 ) ) ; // switch on/off Digit3   
 
     digitalWrite(DigitSecond2, ( i == 3 ) ) ; // switch on/off Digit4

     delay(5);
  }
}

Test it by calling showNumber(1234).
If that works, try showNumber( (100 * 12) + 34) then finally in your sketch
showNumber( (100 * counterFirst) + counterSecond)

Unfortunately it doesnt work.
I have tested it by calling showNumber(1234) and showNumber( (100 * 12) + 34) and it works, but when i write showNumber( (100 * counterFirst) + counterSecond) it just shows the first counter.

To find out what is wrong I deleted all the pushbuttons readings in the loop section and just wrote counterFirst = 12; and counterSecond = 34; and again it just shows number 12 which is counterFirst.
After that I wrote counterFirst = 1234; and it showed number 1234 on the displays.

This is really weird, do you know maybe what could be the problem?

Here is the code how I tested it:

const byte  latchPin = 5;  // Pin connected to Pin 12 of 74HC595 (Latch)
const byte dataPin  = 6;   // Pin connected to Pin 14 of 74HC595 (Data)
const byte clockPin = 7;   // Pin connected to Pin 11 of 74HC595 (Clock)


const byte DigitFirst1 = 2;     // transistor for ones digit of  connected to pin 2(first counter)
const byte DigitFirst2 = 3;     // transistor for tens digit connected to pin 3 (first counter)
const byte DigitSecond1 = 8;     // transistor for ones digit of  connected to pin 8(second counter)
const byte DigitSecond2 = 9;     // transistor for tens digit connected to pin 9(second counter)

int counterFirst = 0;           // initialise first counter as zero
int counterSecond = 0;           // initialise second counter as zero

byte numberOfDigits = 4;

const byte numbers[10] =   // Describe each digit in terms of display segments  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
{
  B11111100, //0
  B01100000, //1
  B11011010, //2
  B11110010, //3
  B01100110, //4
  B10110110, //5
  B10111110, //6
  B11100000, //7
  B11111110, //8
  B11110110, //9
};

void setup()
{
  pinMode(latchPin, OUTPUT);   // set SR pins to output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  pinMode(DigitFirst1, OUTPUT);
  pinMode(DigitFirst2, OUTPUT);

  pinMode(DigitSecond1, OUTPUT);
  pinMode(DigitSecond2, OUTPUT);
  
}

void loop()
{

  counterFirst = 12 ;
  counterSecond = 34;
  
  
  showNumber( counterFirst);           // display the current digit 
}

void showNumber(int number)
{
  

  for(byte i = 0; i < numberOfDigits; i++)
  {
   
    digitalWrite(DigitFirst1, LOW ) ;   // switch off Digit1(ones)
    digitalWrite(DigitFirst2, LOW ) ;   // switch off Digit2(tens)
    digitalWrite(DigitSecond1, LOW ) ;   // switch off Digit3(hundreds)
    digitalWrite(DigitSecond2, LOW ) ;   // switch off Digit4(thousands)

    digitalWrite(latchPin, LOW);   // Set latchPin LOW while clocking bits in to the register

    shiftOut(dataPin, clockPin, LSBFIRST, numbers[number % 10]);
    number /= 10;

   digitalWrite(latchPin, HIGH);     //set latchPin to high to lock and send data

     digitalWrite(DigitFirst1, ( i == 0 ) ) ; // switch on/off Digit1   
 
     digitalWrite(DigitFirst2, ( i == 1 ) ) ; // switch on/off Digit2

     digitalWrite(DigitSecond1, ( i == 2 ) ) ; // switch on/off Digit3   
 
     digitalWrite(DigitSecond2, ( i == 3 ) ) ; // switch on/off Digit4

     delay(2);
  }
}

The code snippet you've include would, of course, only display the value of counterFirst, since that is the only value that showNumber() knows about.:

void loop()
{

  counterFirst = 12 ;
  counterSecond = 34;
 
 
  showNumber( counterFirst);           // display the current digit
}

But, if you say that the calling showNumber(1234) works, then the problem is not with showNumber(), it is with the way you have prepared the values of counterFirst and counterSecond in preparation for the call to showNumber().
Can you post the entire code which demonstrates a failed attempt to display the values of both counterFirst and counterSecond.

I have tested it by calling showNumber(1234) and showNumber( (100 * 12) + 34) and it works, but when i write showNumber( (100 * counterFirst) + counterSecond) it just shows the first counter.

No idea unless you post the version that actually fails...

BTW if your sketch does other time-consuming things it is better to use a digit display
routine that leaves everything switched off outside its call, otherwise the last digit
to update will end up brighter if significant time is spent elsewhere:

byte digit_pins [] = { DigitFirst1, DigitFirst2, DigitSecond1, DigitSecond2 } ;

void showNumber(int number)
{
  for(byte i = 0; i < numberOfDigits; i++)
  {
    digitalWrite(latchPin, LOW);   // Set latchPin LOW while clocking bits in to the register
    shiftOut(dataPin, clockPin, LSBFIRST, numbers[number % 10]);
    number /= 10;
    digitalWrite(latchPin, HIGH);     //set latchPin to high to lock and send data

    digitalWrite (digit_pins[i], HIGH) ;
    delay (2) ;
    digitalWrite (digit_pins[i], LOW) ; 
  }
}

Here is the entire code:

const byte  latchPin = 5;  // Pin connected to Pin 5 of 74HC595 (Latch)
const byte dataPin  = 6;   // Pin connected to Pin 6 of 74HC595 (Data)
const byte clockPin = 7;   // Pin connected to Pin 7 of 74HC595 (Clock)

const byte OneUpPinFirst = 12;     // pushbutton connected to pin 12 for increment by 1 (first counter)
const byte OneDownPinFirst = 13;   // pushbutton connected to pin 13 for decrement by 1 (first counter)


const byte OneUpPinSecond = A1;     // pushbutton connected to pin A1 for increment by 1 (second counter)
const byte OneDownPinSecond = A2;   // pushbutton connected to pin A2 for decrement by 1 (second counter)


const byte DigitFirst1 = 8;     // transistor for ones digit of  connected to pin 8(first counter)
const byte DigitFirst2 = 9;     // transistor for tens digit connected to pin 9 (first counter)
const byte DigitSecond1 = 2;     // transistor for ones digit of  connected to pin 2(second counter)
const byte DigitSecond2 = 3;     // transistor for tens digit connected to pin 3 (second counter)

const byte reset = A0;
int res = 0;


int prevOneUpStateFirst = 0;
int prevOneDownStateFirst = 0;
int currOneUpStateFirst = 1;
int currOneDownStateFirst = 1;


int prevOneUpStateSecond = 0;
int prevOneDownStateSecond = 0;
int currOneUpStateSecond = 1;
int currOneDownStateSecond = 1;

int counterFirst = 0;           // initialise first counter as zero
int counterSecond = 0;           // initialise second counter as zero

byte numberOfDigits = 4;

const byte numbers[10] =   // Describe each digit in terms of display segments  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
{
  B11111100, //0
  B01100000, //1
  B11011010, //2
  B11110010, //3
  B01100110, //4
  B10110110, //5
  B10111110, //6
  B11100000, //7
  B11111110, //8
  B11110110, //9
};

void setup()
{
  pinMode(latchPin, OUTPUT);   // set shift registers pins to output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  pinMode(OneUpPinFirst, INPUT);     
  pinMode(OneDownPinFirst, INPUT);    
  pinMode(DigitFirst1, OUTPUT);
  pinMode(DigitFirst2, OUTPUT);

  pinMode(OneUpPinSecond, INPUT);      
  pinMode(OneDownPinSecond, INPUT);          
  pinMode(DigitSecond1, OUTPUT);
  pinMode(DigitSecond2, OUTPUT);

   pinMode(reset, INPUT);
  
}

void loop()
{
  //counter part
  //first counter
  
  currOneUpStateFirst = digitalRead(OneUpPinFirst);
  if (prevOneUpStateFirst != currOneUpStateFirst)           // has the state changed from HIGH to LOW or vice versa 
  {                                         
    prevOneUpStateFirst = !prevOneUpStateFirst;             //invert
    if (currOneUpStateFirst == HIGH && counterFirst <= 99)  // If the button was pressed AND not reached 99
        counterFirst++;                                     // increment the counter by one

    if(counterFirst > 99) counterFirst = 0;                 //if counter is greater than 99, set it to 0

  }

  currOneDownStateFirst = digitalRead(OneDownPinFirst);
  if (prevOneDownStateFirst != currOneDownStateFirst)        // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevOneDownStateFirst = currOneDownStateFirst;
    if (currOneDownStateFirst == HIGH && counterFirst >= 0)  // If the button was pressed AND not reached 0
        counterFirst--;                                      // decrement the counter by one  
    if(counterFirst < 0) counterFirst = 99;                  // counting backward from 99 to 0

  }

  

//second counter

  currOneUpStateSecond = digitalRead(OneUpPinSecond);
  if (prevOneUpStateSecond != currOneUpStateSecond)           // has the state changed from HIGH to LOW or vice versa
  {                                         
    prevOneUpStateSecond = !prevOneUpStateSecond;             //invert
    if (currOneUpStateSecond == HIGH && counterSecond <= 99)  // If the button was pressed AND not reached 99
        counterSecond++;                                      // increment the counter by one

    if(counterSecond > 99) counterSecond = 0;                 //if counter is greater than 99, set it to 0

  }

  currOneDownStateSecond = digitalRead(OneDownPinSecond);
  if (prevOneDownStateSecond != currOneDownStateSecond)        // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevOneDownStateSecond = currOneDownStateSecond;
    if (currOneDownStateSecond == HIGH && counterSecond >= 0)  // If the button was pressed AND not reached 0
        counterSecond--;                                       // decrement the counter by one  
    if(counterSecond < 0) counterSecond = 99;                  // counting backward from 99 to 0

  }

  

  

  res = digitalRead(reset);      //if the reset button was pressed, set the counters to 0
  if(res == HIGH) 
  counterFirst = 0;
  counterSecond = 0;
  
  
  showNumber( (100 * counterFirst)  +   counterSecond);           // display the current digit 
}

void showNumber(int number)
{
  

  for(byte i = 0; i < numberOfDigits; i++)
  {
   
    digitalWrite(DigitFirst1, LOW ) ;   // switch off Digit1(ones)
    digitalWrite(DigitFirst2, LOW ) ;   // switch off Digit2(tens)
    digitalWrite(DigitSecond1, LOW ) ;   // switch off Digit3(hundreds)
    digitalWrite(DigitSecond2, LOW ) ;   // switch off Digit4(thousands)

    digitalWrite(latchPin, LOW);   // Set latchPin LOW while clocking bits in to the register

    shiftOut(dataPin, clockPin, LSBFIRST, numbers[number % 10]);
    number /= 10;

   digitalWrite(latchPin, HIGH);     //set latchPin to high to lock and send data

     digitalWrite(DigitFirst1, ( i == 0 ) ) ; // switch on/off Digit1   
 
     digitalWrite(DigitFirst2, ( i == 1 ) ) ; // switch on/off Digit2

     digitalWrite(DigitSecond1, ( i == 2 ) ) ; // switch on/off Digit3   
 
     digitalWrite(DigitSecond2, ( i == 3 ) ) ; // switch on/off Digit4

     delay(5);
  }
}

6v6gt:
The code snippet you've include would, of course, only display the value of counterFirst, since that is the only value that showNumber() knows about.

My mistake... I acctually wrote showNumber((100*counterFirst) + counterSecond), but anyway, it still wont display counterSecond.

This:

 res = digitalRead(reset);      //if the reset button was pressed, set the counters to 0
  if(res == HIGH)
  counterFirst = 0;
  counterSecond = 0;

Should probably be:

 res = digitalRead(reset);      //if the reset button was pressed, set the counters to 0
  if(res == HIGH) {
  counterFirst = 0;
  counterSecond = 0;
}

I cant believe it...what a stupit mistake...it works now.
Thank you so much for your time !! :wink:

Hello,

I need to add third display in my project.

The only pins left for driving two more transistors for digits are 0(Rx) and 1(Tx).
After connecting transistors to those pins and uploading modified code, I noticed that, after pressing pushbuttons, the display doesnt count as it should.

I read that Rx and Tx can be used as general I/O pins as long as you dont use serial communication (I do not use it).

So does anyone knows what is the problem and how can I use 0 and 1 pins as digital output pins?

Thanks!

Post your code which has the attempts to use pins 0 and 1.
You do realise that you can also use analog pins A0 to A5 as digital pins ?

I use them already.

const byte  latchPin = 7;  // Pin 7 connected to Pin 12 of 74HC595 (Latch)
const byte dataPin  = 8;   // Pin 8 connected to Pin 14 of 74HC595 (Data)
const byte clockPin = 6;   // Pin 6 connected to Pin 11 of 74HC595 (Clock)

const byte OneUpPinFirst = A4;     // pushbutton connected to pin A4 for increment by 1 (first counter)
const byte OneDownPinFirst = A5;   // pushbutton connected to pin A5 for decrement by 1 (first counter)
const byte TenUpPinFirst = A6;     // pushbutton connected to pin A6 for increment by 10 (first counter)
const byte TenDownPinFirst = A7;    // pushbutton connected to pin A7 for decrement by 10 (first counter)

const byte OneUpPinSecond = A0;     // pushbutton connected to pin A0 for increment by 1 (second counter)
const byte OneDownPinSecond = A1;   // pushbutton connected to pin A1 for decrement by 1 (second counter)
const byte TenUpPinSecond = A2;     // pushbutton connected to pin A2 for increment by 10 (second counter)
const byte TenDownPinSecond = A3;    // pushbutton connected to pin A3 for decrement by 10 (second counter)

const byte OneUpPinThird = 10;     // pushbutton connected to pin 10 for increment by 1 (third counter)
const byte OneDownPinThird = 11;   // pushbutton connected to pin 11 for decrement by 1 (thirdcounter)
const byte TenUpPinThird = 12;     // pushbutton connected to pin 12 for increment by 10 (third counter)
const byte TenDownPinThird = 13;    // pushbutton connected to pin 13 for decrement by 10 (third counter)

const byte DigitFirst1 = 5;     // transistor for ones digit connected to pin 0(first counter)
const byte DigitFirst2 = 4;     // transistor for tens digit connected to pin 1 (first counter)
const byte DigitSecond1 = 3;     // transistor for ones digit connected to pin 2(second counter)
const byte DigitSecond2 = 2;     // transistor for tens digit connected to pin 3 (second counter)
const byte DigitThird1 = 1;     // transistor for ones digit connected to pin 4(third counter)
const byte DigitThird2 = 0;     // transistor for tens digit connected to pin 5 (third counter)

const byte reset = 9;
int resetState = 0;
long holdTime = 0;



int prevOneUpStateFirst = 0;
int prevTenUpStateFirst = 0;
int prevOneDownStateFirst = 0;
int prevTenDownStateFirst = 0;
int currOneUpStateFirst = 1;
int currTenUpStateFirst = 1;
int currOneDownStateFirst = 1;
int currTenDownStateFirst = 1;

int prevOneUpStateSecond = 0;
int prevTenUpStateSecond = 0;
int prevOneDownStateSecond = 0;
int prevTenDownStateSecond = 0;
int currOneUpStateSecond = 1;
int currTenUpStateSecond = 1;
int currOneDownStateSecond = 1;
int currTenDownStateSecond = 1;

int prevOneUpStateThird = 0;
int prevTenUpStateThird = 0;
int prevOneDownStateThird = 0;
int prevTenDownStateThird = 0;
int currOneUpStateThird = 1;
int currTenUpStateThird = 1;
int currOneDownStateThird = 1;
int currTenDownStateThird = 1;


int counterFirst = 0;           // initialise first counter as zero
int counterSecond = 0;           // initialise second counter as zero
int counterThird = 0;           // initialise third counter as zero


byte numberOfDigits = 6;

const byte numbers[10] =   // Describe each digit in terms of display segments  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
{
  B11111100, //0
  B01100000, //1
  B11011010, //2
  B11110010, //3
  B01100110, //4
  B10110110, //5
  B10111110, //6
  B11100000, //7
  B11111110, //8
  B11110110, //9
};
void setup()
{
  pinMode(latchPin, OUTPUT);   // set shift registers pins to output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  pinMode(OneUpPinFirst, INPUT);     
  pinMode(OneDownPinFirst, INPUT);    
  pinMode(TenUpPinFirst, INPUT);
  pinMode(TenDownPinFirst, INPUT);
  pinMode(DigitFirst1, OUTPUT);
  pinMode(DigitFirst2, OUTPUT);

  pinMode(OneUpPinSecond, INPUT);      
  pinMode(OneDownPinSecond, INPUT);  
  pinMode(TenUpPinSecond, INPUT);
  pinMode(TenDownPinSecond, INPUT);         
  pinMode(DigitSecond1, OUTPUT);
  pinMode(DigitSecond2, OUTPUT);

  
  pinMode(OneUpPinThird, INPUT);      
  pinMode(OneDownPinThird, INPUT);  
  pinMode(TenUpPinThird, INPUT);
  pinMode(TenDownPinThird, INPUT);         
  pinMode(DigitThird1, OUTPUT);
  pinMode(DigitThird2, OUTPUT);

   pinMode(reset, INPUT);
   
}

void loop()
{
  //counter part
  
  //first counter
  
  currOneUpStateFirst = digitalRead(OneUpPinFirst);
  if (prevOneUpStateFirst != currOneUpStateFirst)           // has the state changed from HIGH to LOW or vice versa 
  {                                         
    prevOneUpStateFirst = !prevOneUpStateFirst;             //invert
    if (currOneUpStateFirst == HIGH && counterFirst < 99)  // If the button was pressed AND not reached 99
        counterFirst++;                                     // increment the counter by one
  }

  currOneDownStateFirst = digitalRead(OneDownPinFirst);
  if (prevOneDownStateFirst != currOneDownStateFirst)        // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevOneDownStateFirst = currOneDownStateFirst;
    if (currOneDownStateFirst == HIGH && counterFirst > 0)  // If the button was pressed AND not reached 0
        counterFirst--;                                      // decrement the counter by one 
  }

 currTenUpStateFirst = digitalRead(TenUpPinFirst);
  if (prevTenUpStateFirst != currTenUpStateFirst)           // has the state changed from HIGH to LOW or vice versa
  {                                         
    prevTenUpStateFirst = !prevTenUpStateFirst;             //invert
    if (currTenUpStateFirst == HIGH && counterFirst < 90)  // If the button was pressed AND not reached 99
        counterFirst = counterFirst + 10;                   // increment the counter by ten
  }
  
  currTenDownStateFirst = digitalRead(TenDownPinFirst);
  if (prevTenDownStateFirst != currTenDownStateFirst)       // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevTenDownStateFirst = currTenDownStateFirst;
    if (currTenDownStateFirst == HIGH && counterFirst >= 10) // If the button was pressed AND not reached 0
        counterFirst = counterFirst - 10;                   // decrement the counter by ten  
  }



//second counter

  currOneUpStateSecond = digitalRead(OneUpPinSecond);
  if (prevOneUpStateSecond != currOneUpStateSecond)           // has the state changed from HIGH to LOW or vice versa
  {                                         
    prevOneUpStateSecond = !prevOneUpStateSecond;             //invert
    if (currOneUpStateSecond == HIGH && counterSecond < 99)  // If the button was pressed AND not reached 99
        counterSecond++;                                      // increment the counter by one
  }

  currOneDownStateSecond = digitalRead(OneDownPinSecond);
  if (prevOneDownStateSecond != currOneDownStateSecond)        // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevOneDownStateSecond = currOneDownStateSecond;
    if (currOneDownStateSecond == HIGH && counterSecond > 0)  // If the button was pressed AND not reached 0
        counterSecond--;                                       // decrement the counter by one  
  }

  currTenUpStateSecond = digitalRead(TenUpPinSecond);
  if (prevTenUpStateSecond != currTenUpStateSecond)           // has the state changed from HIGH to LOW or vice versa
  {                                         
    prevTenUpStateSecond = !prevTenUpStateSecond;             //invert
    if (currTenUpStateSecond == HIGH && counterSecond < 90)  // If the button was pressed AND not reached 99
        counterSecond = counterSecond + 10;                   // increment the counter by ten
  }
  
  currTenDownStateSecond = digitalRead(TenDownPinSecond);
  if (prevTenDownStateSecond != currTenDownStateSecond)       // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevTenDownStateSecond = currTenDownStateSecond;
    if (currTenDownStateSecond == HIGH && counterSecond >= 10) // If the button was pressed AND not reached 0
        counterSecond = counterSecond - 10;                   // decrement the counter by ten  
  }



//third counter

  currOneUpStateThird = digitalRead(OneUpPinThird);
  if (prevOneUpStateThird != currOneUpStateThird)           // has the state changed from HIGH to LOW or vice versa
  {                                         
    prevOneUpStateThird = !prevOneUpStateThird;             //invert
    if (currOneUpStateThird == HIGH && counterThird < 99)  // If the button was pressed AND not reached 99
        counterThird++;                                      // increment the counter by one
  }

  currOneDownStateThird = digitalRead(OneDownPinThird);
  if (prevOneDownStateThird != currOneDownStateThird)        // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevOneDownStateThird = currOneDownStateThird;
    if (currOneDownStateThird == HIGH && counterThird > 0)  // If the button was pressed AND not reached 0
        counterThird--;                                       // decrement the counter by one 
  }

  currTenUpStateThird = digitalRead(TenUpPinThird);
  if (prevTenUpStateThird != currTenUpStateThird)           // has the state changed from HIGH to LOW or vice versa
  {                                         
    prevTenUpStateThird = !prevTenUpStateThird;             //invert
    if (currTenUpStateThird == HIGH && counterThird < 90)  // If the button was pressed AND not reached 99
        counterThird = counterThird + 10;                   // increment the counter by ten
  }
  
  currTenDownStateThird = digitalRead(TenDownPinThird);
  if (prevTenDownStateThird != currTenDownStateThird)       // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevTenDownStateThird = currTenDownStateThird;
    if (currTenDownStateThird == HIGH && counterThird >= 10) // If the button was pressed AND not reached 0
        counterThird = counterThird - 10;                   // decrement the counter by ten  
  }
  resetState = digitalRead(reset);      //if the reset button is pressed for 1sec, set the counters to 0
  if(resetState == HIGH && (millis() - holdTime) >= 1000){
    counterFirst = 0;
    counterSecond = 0;
    counterThird = 0;
  }
  
  else if(resetState == LOW){
    holdTime = millis();
  }
  showNumber(counterThird + (100 * counterSecond) + (10000 * counterFirst));           // display the current digit 
}

void showNumber(int number)
{
  

  for(byte i = 0; i < numberOfDigits; i++)
  {
   
    digitalWrite(DigitFirst1, LOW ) ;   // switch off Digit1(ones)
    digitalWrite(DigitFirst2, LOW ) ;   // switch off Digit2(tens)
    digitalWrite(DigitSecond1, LOW ) ;   // switch off Digit3(hundreds)
    digitalWrite(DigitSecond2, LOW ) ;   // switch off Digit4(thousands)
    digitalWrite(DigitThird1, LOW ) ;   // switch off Digit5(ten thousands)
    digitalWrite(DigitThird2, LOW ) ;   // switch off Digit6(hundred thousands)

    digitalWrite(latchPin, LOW);   // Set latchPin LOW while clocking bits in to the register

    shiftOut(dataPin, clockPin, LSBFIRST, numbers[number % 10]);
    number /= 10;

   digitalWrite(latchPin, HIGH);     //set latchPin to high to lock and send data

     digitalWrite(DigitFirst1, ( i == 0 ) ) ; // switch on/off Digit1   
 
     digitalWrite(DigitFirst2, ( i == 1 ) ) ; // switch on/off Digit2

     digitalWrite(DigitSecond1, ( i == 2 ) ) ; // switch on/off Digit3   
 
     digitalWrite(DigitSecond2, ( i == 3 ) ) ; // switch on/off Digit4
     
     digitalWrite(DigitThird1, ( i == 4 ) ) ; // switch on/off Digit5   
 
     digitalWrite(DigitThird2, ( i == 5 ) ) ; // switch on/off Digit5


     delay(2);
  }
}

I see you have a lot of pins occupied by buttons.

Instead of doing something like this:

const byte OneUpPinSecond = A0;     // pushbutton connected to pin A0 for increment by 1 (second counter)
const byte OneDownPinSecond = A1;   // pushbutton connected to pin A1 for decrement by 1 (second counter)
const byte TenUpPinSecond = A2;     // pushbutton connected to pin A2 for increment by 10 (second counter)
const byte TenDownPinSecond = A3;    // pushbutton connected to pin A3 for decrement by 10 (second counter)

You could use 1 analog pin and 5 resistors in series:

+5v --> R1 --> R2 --> R3 --> R4 -->( A0 connected here )--> R0 --> GND

Each button is connected across one of the resistors R1 to R4 so when pressed, it shorts out the resistor it is connected to. By checking the analog voltage range on A0, you can see which button(s) were pressed. Values like the following should work:
R1: 10K
R2: 20K
R3: 40K
R4: 80K
R5: 80K
Connect a capacitor say 100nF across R0.

I don't see why you should have a problem using D0 and D1 since you are not using Serial functions.

Could you please show me an example of reading analog voltage range?

Something like this. You have to determine the number ranges by either calculation or be experiment.

int ar ;
int buttonPressed = 0 ;

ar = analogRead( A0 ) ;   

if ( ar > 400 && ar <= 500 ) {
     buttonPressed = 1 ;
}
else if ( ar > 300 && ar <= 400 ) {
     buttonPressed = 2 ;
}
else if ( ar > 200 && ar <= 300 ) {
     buttonPressed = 3 ;
}
else if ( ar > 100 && ar <= 200 ) {
     buttonPressed = 4 ;
}

I will try that...thank you

I am trying to figure out why display wont work on the D0 and D1 pins so I removed third display and, as before, used just two. I connected two transistors of one display to the D0 and D1 pins and it actually worked...
So I returned again third display and tried to test it as you said me to test the code with 2 displays:

 showNumber(123456);           // display the current digit

When I upload it I get the message: warning: overflow in implicit constant conversion [-Woverflow] , and nothing shows up on the displays...

But when I write this :

showNumber(counterThird + (100 * counterSecond) + (10000 * counterFirst));           // display the current digit

two displays counts normally, but everything stops working at some point when I try to count with third display... :frowning:

So its not problem with D0 and D1 pins...

What does this warning means?

SOLVED!!

Number 123456 is too big for integer!

Changed this:

  showNumber(123456);           // display the current digit 
}

void showNumber(int number)
{

To this:

  showNumber(123456);           // display the current digit 
}

void showNumber(unsigned long number)
{

One last think...

I need to use A6 and A7 pins on my arduino nano as button inputs...
They can be used just for analog input so I write this to read the value from buttons:

currTenUpStateFirst = analogRead(TenUpPinFirst);
  if (prevTenUpStateFirst != currTenUpStateFirst)           // has the state changed from HIGH to LOW or vice versa
  {                                         
    prevTenUpStateFirst = !prevTenUpStateFirst;             //invert
    if (currTenUpStateFirst > 1020 && counterFirst < 90)  // If the button was pressed AND not reached 99
        counterFirst = counterFirst + 10;                   // increment the counter by ten
  }
  
  currTenDownStateFirst = analogRead(TenDownPinFirst);
  if (prevTenDownStateFirst != currTenDownStateFirst)       // has the state changed from HIGH to LOW or vice versa
  {                                                 
    prevTenDownStateFirst = currTenDownStateFirst;
    if (currTenDownStateFirst > 1020 && counterFirst >= 10) // If the button was pressed AND not reached 0
        counterFirst = counterFirst - 10;                   // decrement the counter by ten  
  }

What happens is next...when I press the button it quickly counts from 0 to 90(and vice versa), unlike on the other digital pins where even if I hold the button it just increments/decrements by 10.

How could I change this so it would increment/decrement only by 10 no matter how long i hold the button?

Thank you!