button press 2 digit 7 segment help

Hi,

I am trying to change the seven segment display with 2 shift registers to on a button push increment by 5 as appose to incrementally by one.

can anyone tell me can i do this via the counter, i have tried counter =5; but when ever you press the button it goes back to 5.
do i need to do another void function with a separate shift out.

The up button incrementally changes the display numbers one at a time.

any help would be great.

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 upPin = 12;      // pushbutton attached to pin 12
const byte downPin = 13;      // pushbutton attached to pin 13
bool prevUpState = 0;
bool prevDownState = 0;
int currUpState = 1;
int currDownState = 1;
int counter = 0;          // initialise counter as zero

//Min and max value of the counter
const byte maxCount = 100;
const byte minCount = 0;

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,
  B01100000,
  B11011010,
  B11110010,
  B01100110,
  B10110110,
  B10111110,
  B11100000,
  B11111110,
  B11100110,
};

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_PULLUP);   // sets pin 13 as pushbutton INPUT
}

void loop()
{
  //counter part
  currUpState = digitalRead(upPin);// <== NO need for stupid global
  if (prevUpState != currUpState)           // has the state changed from
  { // HIGH to LOW or vice versa
    prevUpState = !prevUpState; //invert
    if (currUpState == HIGH && counter < maxCount)                  // If the button was pressed AND not reached limit
      counter++;
   
    if(counter == maxCount) counter = 0;     // increment the counter by one <=== LIMITS IT TO 8 NOW!

  }
  /* useless bit of code
  if (counter > 8)
    counter--;
  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 && counter > minCount)                // If the button was pressed AND not reached limit
       counter--;                         // decrement the counter by one

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

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

This line

      counter++;

is the same as

      counter=counter +1;

Now it should be easy for you to modify the code to increase counter by 5 steps at at time instead of 1.

Why didn't you use INPUT_PULLUP on both of these?

pinMode(upPin, INPUT); // sets pin 12 as pushbutton INPUT
pinMode(downPin, INPUT_PULLUP); // sets pin 13 as pushbutton INPUT

The pin could be floating and giving you erratic results.

Brilliant thanks very much!!!

@crossroads thanks for the advice, i will fix that, i had a 10k resistor on one button and noticed i was out of 10k resistors for the second button.