We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › time between events
Page Index Toggle Pages: 1
time between events (Read 449 times)
time between events
Nov 27th, 2007, 4:50am
 
hi,

I'm looking to find a way of printing the time elapsed between two successive interactive events, eg. keys being pressed. However, I have no idea where to even start.
Any pointers would be greatly appreciated. Thanks.
Re: time between events
Reply #1 - Nov 27th, 2007, 6:17am
 
Hi. See the millis() method reference :
http://processing.org/reference/millis_.html

Call the method at two different times and make a substraction : you'll get the time ellapsed between the two events.

Code:
float t1 = millis();
// do stuff...
float t2 = millis();
float timeEllapsed = t2 - t1; // time ellapsed in milliseconds
Re: time between events
Reply #2 - Nov 27th, 2007, 1:05pm
 
thanks i'll try that. i had looked at the millis() method but had discarded it, thinking that it would only count from when the applet opened. I didn't think it counted from each time you called it.
Re: time between events
Reply #3 - Nov 27th, 2007, 3:40pm
 
It does only count millis since the sketch was run, but you can then store the result in an int, and compare the urrent value returned by millis() and your stored value.
Re: time between events
Reply #4 - Nov 28th, 2007, 2:06am
 
ah i get it now. that makes sense. thanks again guys.
Page Index Toggle Pages: 1