I am looking for a way to increment a variable by one each time a button is pressed. Current approach is the following :
if (redButton.isPressed())
{
a++;
delay(100);
}
isPressed()
just return true if the pin state is HIGH.
delay(100)
is used to compensate the small amount of time the button is being pressed. Otherwise a
would be incremented multiple times in a single press. But it's blocking behavior, my program can't do anything else during that delay.
In short I'm looking to add a method in my Button class to detect if the button "has just been released".