Start timing when event occurs, stop when event finishes, measure time, how?

Hello! I have been looking at all the interrupts and timers and was hoping someone here could point me in the right direction. I have an event (a clap) which goes the entire analog input range. The baseline sound input hovers at around 2 V. In order to differentiate the clap from other ambient sound like loud talking, I thought to put a time component on it. So that the clap is defined as going from 10 to 1000 on A0 and has an interval of 40 ms.

1) Does this sound like a good way to define a clap input? 2) Which interrupt/timer can be used to start when the clap occurs and times its duration

Thanks in advance

How fast is this event? The millis() function will return the number of seconds since the board was reset last. If you record that time at the beginning and end of the event, then you can just subtract the two to get the length of time between.

But you can't reset milllis() to zero. Do I need to? The event is about 40 ms.

Do you need to reset your watch to midnight any time you want to know how long you've been driving somewhere?

If the millis counter was at 300ms when the event started and is at 350ms at the end, then how long was the event?

Sophi:
But you can’t reset milllis() to zero. Do I need to?
The event is about 40 ms.

No. We take the differences between times by subtracting using unsigned math.
If you look at a clock face, it’s unsigned. Subtract 11 from 2 is 3 hours.
Arduino millis() is 32 bit unsigned, the clock can time milliseconds for 49.7 days of difference.

unsigned long startMillis, elapsedMillis, waitMillis = 1000UL;

digitalRead( pin );
startMillis = millis();

… later on

elapsedMillis = millis() - startMillis;

if ( millis() - startMillis >= waitMillis )
{
// do regularly repeated action
startMillis() += waitMillis;
}

Thank you, works great

The millis() function will return the number of seconds since the board was reset last.

Really? That's not what my copy of millis() returns.

PaulS: Really? That's not what my copy of millis() returns.

Oops. Milliseconds I mean.

I made that same mistake at work a few days ago and wrote millimeter when i meant centimeter and cost myself half a day.