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 & HelpPrograms › microsecond
Page Index Toggle Pages: 1
microsecond (Read 536 times)
microsecond
Jul 6th, 2007, 9:29am
 
to get a distance i need to measure the time-of-flight of an ultrasonic pulse. a millisecond corresponds to 34 cm which is not accurate enough for my application. is there a way to get down to the microsecond?
thanks for your help!
Re: microsecond
Reply #1 - Jul 6th, 2007, 2:56pm
 
Not through processing directly, but Java 1.5 and greater have the System.nanoTime() method, which may or may not give you useful information (no guarantees are made as to how often the nanotimer is updated).  See http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#nanoTime()  for information.

If you'd rather not follow the link, try this, which is the example there:

  long startTime = System.nanoTime();
  // ... the code being measured ...
  long estimatedTime = System.nanoTime() - startTime;

May at least give you somewhere to start...though if you're targeting 1.4, you're probably out of luck unless you want to do some native method hacking.
Page Index Toggle Pages: 1