Counting the amount of BOOT button presses within a 5 second timeframe

Hello, I am trying to write some code which will count the amount of times the BOOT button is pressed within 5 seconds during the setup phase. I have made an attempt below trying to utilize the "millis()" function (Code snippet):

while(delayCount <= 5)
{
buttonState = digitalRead(bootButton);

if(buttonState == HIGH && currentTime == 500)
{
currentTime = millis();
if(currentTime >= (loopTime + 5000))
{
if(buttonState != lastButtonState)
{
if(buttonState == HIGH)
{
buttonCount++;
}
delay(50);
}
lastButtonState = buttonState;
delayCount++;
}
}
}

if((buttonCount % 2) == 0)
{
directionDefine = true;
}
else
{
directionDefine = false;
}
}

With the following variable declarations:
int bootButton = 27;
int lastError = 0;

int buttonCount = 0;
int delayCount = 0;
int buttonState = 0;
int lastButtonState = 0;
bool directionDefine; //True = Right, False = Left

int loopTime = 0;
int currentTime = 0;

But I'm lost about how to go about it :frowning: Any help would be greatly appreciated

Set up a button function

bool button() {
  static int lastButtonState;
  static unsigned long buttonDebounceTimestamp;
  int buttonState = digitalRead(ButtonPin);
  if (buttonState != lastButtonState && buttonState == LOW) {// transition is HIGH to LOW
    if (millis() - buttonDebounceTimestamp >= 250UL) {// 250UL = 250ms = time for debounce
      lastButtonState = buttonState;
      buttonDebounceTimestamp = millis();
      return true;
    }
    else {
      lastButtonState = buttonState;
      return false;
    }
  }
  else {
    lastButtonState = buttonState;
    return false;
  }
}

Then take it as a condition to your count

if (button()) count++;