To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.javaOpen lugnet.robotics.rcx.java in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / Java / 210
209  |  211
Subject: 
Re: Help with Clock
Newsgroups: 
lugnet.robotics.rcx.java
Date: 
Tue, 3 Sep 2002 03:56:34 GMT
Viewed: 
4333 times
  
In lugnet.robotics.rcx.java, Scott Makos writes:
I am using legjos and...

having problems understanding the clock/timers.

1.  Are their only one timer clock?

2.  How do you acess the timers clock?  What code would I use?



Scott
Here is a Stopwatch class that does the sort of thing that Jeurgen discussed
in his message.  You can instantiate as many stopwatches as you want to keep
track of the elapsed time between different events.



import josx.platform.rcx.*;

/**
* Elapsed time watch (in milliseconds) <br>
* To use - construct a new instance.
*  @author Roger Glassey
*  version 2
*/
public class Stopwatch{
/**
records system clock time (in milliseconds) when reset() was executed
*/
private int t0 = 0;

/**
constructor: make a new stopwatch and reset it
*/
public Stopwatch() { reset();}
/**
Reset watch to zero
*/
public void reset(){
t0 = ((int)System.currentTimeMillis());
}
/**
Return elapsed time in milliseconds
*/
public int elapsed( ){
return ((int)System.currentTimeMillis()) -t0;
}

/**
This method returns after  delay   milliseconds
*/
public void wait(int delay) {
reset();
while (elapsed()<delay);
}


}



Message has 1 Reply:
  Re: Help with Clock
 
(...) Interesting, I should browse through the classes every now and then ... One thing to note is that josx.platform.rcx is not the right place for it, as it is independent of the RCX platform (maybe josx.util ?). (...) I think it would be better (...) (22 years ago, 3-Sep-02, to lugnet.robotics.rcx.java)

Message is in Reply To:
  Help with Clock
 
I am using legjos and... having problems understanding the clock/timers. 1. Are their only one timer clock? 2. How do you acess the timers clock? What code would I use? Scott (22 years ago, 29-Aug-02, to lugnet.robotics.rcx.java)

6 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR