The following code allows for the measurement of the time interval in milliseconds between two button pressing (without debouncing).
const int buttonPin = 2;
unsigned long buttonTimer, timeInterval;
boolean counting = false;
void setup ()
{
Serial.begin(9600);
}
void loop ()
{
if (digitalRead (buttonPin) == HIGH && counting == false)
{
Serial.println("Start lapse...");
buttonTimer = millis ();
counting = true;
delay(200);
}
if (digitalRead (buttonPin) == HIGH && counting == true)
{
timeInterval = millis () - buttonTimer;
Serial.print("Stop. Time elapsed: ");
Serial.print(timeInterval);
Serial.println(" msec");
counting = false;
delay(200);
}
}
I used the same circuit from the Arduino debounce tutorial
Regards, Palliser