consider
const byte pinBut = A1;
byte butState = HIGH;
unsigned long msecLst;
int count;
// -----------------------------------------------------------------------------
void
loop (void)
{
unsigned long msec = millis ();
#define Timeout 5000
if ( (msec - msecLst) > Timeout) {
msecLst = msec;
Serial.println (count);
count = 0;
}
if (butState != digitalRead (pinBut)) {
butState = ! butState;
if (LOW == butState)
count++;
}
}
// -----------------------------------------------------------------------------
void
setup (void)
{
Serial.begin (9600);
pinMode (pinBut, INPUT_PULLUP);
}