Measuring time lapses

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

I'd note the time before calling a potentially blocking function like print.

check - Arduino Playground - StopWatchClass -

Palliser:
The following code allows for the measurement of the time interval in milliseconds between two button pressing (without debouncing).

But you are de-bouncing as the time to service the Serial.print(s) and the delay(200) before reading the button again means the switch contacts will/should have stopped bouncing.