The following should do the trick if a button press causes the input to go high. If a press causes the input to go low, then you will have to edit pines 70 and 75.
Note: The debouncing function I wrote was quick, untested, and blocking (~8ms of delay). You can change it to become non-blocking if you want.
const byte latchPin = 7;
const byte dataPin = 4;
const byte clockPin = 8;
byte button = 13;
byte counter = 0;
byte previousState = 0;
int number_array[16] = // 0-9 A-F
{
B11111100,//0
B01100000,//1
B11011010,//2
B11110010,//3
B01100110,//4
B10110110,//5
B10111110,//6
B11100000,//7
B11111110,//8
B11100110,//9
B11101110,//A
B00111110,//B
B10011100,//C
B01111010,//D
B10011110,//E
B10001110,//F
};
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(button, INPUT);
debounce(button);
writeToRegister (counter);
}
void loop()
{
debounce(button, previousState);
if (counter < 16)
{
if (!pressed)
{
counter++;
} writeToShiftRegister(counter);
}
else if (counter == 16)
{
counter = 0;
}
}
void writeToRegister (byte data)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
void debounce(int pin, byte &previousState)
{
byte currentState = 0;
byte pressed = 0;
currentState = digitalRead(pin);
if(currentState && !previousState)
{
while(pressed != 0xFF)
{
delay(1);
pressed = (pressed << 1) | digitalRead(pin);
}
}
previousState = currentState;
}