Scoreboard using push buttons not IR

I’m having trouble changing this code to work with push buttons and not remote IR. If anyone can help it would be awesome. Plus i’m using 74HC4511 and on 2 digit numbers going from 0 - 99 does the code change the number from 9 to 10 or does the chip (74HC4511) do? I do have them daisy chained. file attached

or

Maybe tech me how to code to go from 0 to 99 with led lights (strip leds) I have it going from 0 to 9 and back to 0 but I can’t seem to have it jump to the other 7 led display.

//  7-Segment LED counter, multiplexing using 74HC595 8-bit shift register, increment counter zero to nine to zero via push button switches
// Code mangled together from these sources - thanks fellas

const int latchPin = 5;  // Pin connected to Pin 12 of 74HC595 (Latch)
const int dataPin  = 6;  // Pin connected to Pin 14 of 74HC595 (Data)
const int clockPin = 7;  // Pin connected to Pin 11 of 74HC595 (Clock)
int upPin = 12;      // pushbutton attached to pin 12
int downPin = 13;      // pushbutton attached to pin 12
int currUpState = 1;   // initialise currUpState as HIGH
int currDownState = 1;   // initialise currDownState as HIGH
int prevUpState = 0;
int prevDownState = 0;
int counter = 0;          // initialise counter as zero
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
B11100110, //9
};


void setup()
  {
  pinMode(latchPin, OUTPUT);   // set SR pins to output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(upPin, INPUT);   // sets pin 12 as pushbutton INPUT
  pinMode(downPin, INPUT);   // sets pin 13 as pushbutton INPUT
  }
  void loop()
    {
    currUpState = digitalRead(upPin);
    
    if (prevUpState != currUpState)             // has the state changed from
      {                                           // HIGH to LOW or vice versa
      prevUpState = currUpState;
      
    if (currUpState == HIGH)                  // If the button was pressed
    counter++;          // increment the counter by one
    //delay(1);
    }
    
    if(counter > 99)
    counter-=1;
    show(numbers[counter]); // display the current digit
    currDownState = digitalRead(downPin);
    
    if (prevDownState != currDownState)         // has the state changed from
    {                                           // HIGH to LOW or vice versa
    prevDownState = currDownState;
    if (currDownState == HIGH)                // If the button was pressed
    counter-=1;                              // decrement the counter by one
    //delay(1);
    }
    
    if(counter < 0)
    counter++;
    show(numbers[counter]); // display the current digit
    }
    
void show( byte number)
{
// Use a loop and a bitwise AND to move over each bit that makes up
// the seven segment display (from left to right, A => G), and check
// to see if it should be on or not
  for(int j = 0; j <= 7; j++)
  {
  byte toWrite = number & (B10000000 >> j);
  
  if(!toWrite) {
  continue;
  }  // If all bits are 0 then no point writing it to the shift register,so break out and move on to next segment.
  shiftIt(toWrite); // Otherwise shift it into the register
  }
  }
  
void shiftIt (byte data)
  {
  digitalWrite(latchPin, LOW); // Set latchPin LOW while clocking these 8 bits in to the register
    for (int k=0; k <= 7; k++)
    
   {
   digitalWrite(clockPin, LOW); // clockPin LOW prior to sending a bit
    if ( data & (1 << k) )
      {
      digitalWrite(dataPin, HIGH); // turn “On”
      }
    else
      {
      digitalWrite(dataPin, LOW); // turn “Off”
      }
      
   digitalWrite(clockPin, HIGH); // and clock the bit in
   }
   
digitalWrite(clockPin, LOW);  //stop shifting out data
digitalWrite(latchPin, HIGH); //set latchPin to high to lock and send data
}

Moderator edit: code tags. Always code tags.

Softball_scoreboard.ino (28.6 KB)

Some of your questions require a schematic to answer.

Im looking for code to have these 2 digits go from 0 to 99 and back to 0 with 2 up/down buttons. Then I can figure the rest of the numbers I need later.

Nice picture of wires connecting unlabeled pins of ‘black boxes’ not providing any clue of functionality. How about a schematic? Example (with both common anode and common cathode):
74HC595 and 7 segment displays.png

images.jpg

kaffeetimer_v1_Steckplatine.png

And some code like this, with 2 & 3 connecting to Gnd when pressed

#include <SPI.h>
byte fontArray[] = { dp-g-f-e-d-c-b-a
0b00111111, // 0          a
0b00000110, // 1      f        b
:                          g
:                     e        c
0b01100111, // 9           d       DP
};
byte upButton = 2;
byte downButton = 3;
byte ssPin = 10:

void setup(){
pinMode (ssPin, OUTPUT);
pinMode (upButton, INPUT_PULLUP);
pinMode (downButton, INPUT_PULLUP);
SPI.begin();
}
void loop(){
if (digitalRead(upButton) == LOW){ // increment & rollover
update = 1;
ones = ones +1;
if (ones == 10){
ones = 0;
tens = tens+1;
if (tens == 10){
tens = 0;
}
}
}
if (digitalRead(downButton) == LOW){  // decrement & rollover
update = 1;
if (ones >0){
ones = ones -1;
} 
if (ones == 0 && tens >0){
ones = 9;
tens = tens -1;
}
if (ones == 0 && tens == 0){
ones = 9;
tens = 9;
}
}
}
if (update == 1){
update = 0;
digitalWrite (ssPin, LOW);
SPI.transfer (fontArray[ones]);
SPI.transfer(fontArray[tens]);
digitalWrite (ssPin, HIGH);
}
delay(25); // dumb debounce if needed
}

Too easy …

Sorry for the info I gave above but that's what I started with. I just started into Arduino so I don't know the in's and out's but I have done small projects and I seem to build them off codes I dig up off the net.

@CrossRoads I have read other post where you have a board that can support 12 digits? If so can I buy one with code for 4 2-digit to count from 0-99 then from 99-0 with up button and down button and 1 1-digit number form 0-9 and back from 9-0 with buttons. I will be using LED strips with common anode 12v with Tip120.

All i'm trying to do is help the kids at the local game park have a scoreboard because they can't afford one. They need Home score (0-99), Visitor score (0-99), 2 pitch count (0-99) and a inning (1-9) I can add the strikes, balls and outs from left over pins on a MEGA2560 R3 but if you could add them in the code I would pay for your time.

I'm just a normal guy trying to help and if I had the money I would just buy them a new one.
Any help would be appreciated.

You should look at the shiftOut() function, it would simplify your code. I think that in your setup you only need to shift out the tens byte then the ones byte for a two digit number.

So to write a number would be like:

void show(byte number)
{

  byte ones = number % 10;    // 1's digit
  byte tens = number / 10;    // 10's digit

  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, numbers[tens]);
  shiftOut(dataPin, clockPin, LSBFIRST, numbers[ones]);
  digitalWrite(latchPin, HIGH);

}

I would have to setup the hardware to test this, it could be that the bytes are written in the other order, but I'm hoping this is helpful.

I built a similar setup to yours and the following code works. My constants are different than yours, so change them to match your setup. It’s not clear to me if you should pass MSBFIRST or LSBFIRST to shiftOut(), so that may need to be changed.

/// Prototype for two digit scoreboard with 7 segment displays

const byte numbers[10] =  // Describe each digit in terms of display segments  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
{

  B11000000, //0
  B11111001, //1
  B10100100, //2
  B10110000, //3
  B10011001, //4
  B10010010, //5
  B10000011, //6
  B11111000, //7
  B10000000, //8
  B10011000, //9

};


const int latchPin = 8;          // 74HC595 latch
const int clockPin = 12;         // 74HC595 clock
const int dataPin = 11;          // 74HC595 data

const int upPin = 2;      // score +
const int downPin = 3;    // score -

int score = 0;    // current score

void setup() {

  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(upPin, INPUT);
  pinMode(downPin, INPUT);

  // initialize score board
  showScore();

} 

void loop() {

  // if down button pressed
  if( digitalRead(downPin) == HIGH ) {

    // decrement score
    if(score > 0) score--;

    // show score
    showScore();

    delay(150); // debounce 

  } // if

  // if up button pressed
  if( digitalRead(upPin) == HIGH ) {

    // increment score or wrap to zero
    score = (score < 99) ? score+1 : 0;

    // show score
    showScore();

    delay(150); // debounce 

  } // if


}

// showScore
//
// Write two digit score to two 7 segment displays
//
void showScore()
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, numbers[score % 10]);  // ones digit
  shiftOut(dataPin, clockPin, MSBFIRST, numbers[ score / 10]);  // tens digit
  digitalWrite(latchPin, HIGH);

}