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 Any help would be greatly appreciated