Go to Post We are just here to give back to a program that gave us so much as students. - Alex Cormier [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Spotlight this post!  
Unread 09-02-2012, 16:40
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 162
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Re: Set command to run for a certain amount of time

If you don't want something big and fancy like ^ that guy suggested , I would use the FPGA time method in the Utility class.

Code:
long millisecondsToRun = 1000; // This should run 1000ms = 1 s.
long initTime = Utility.getFPGATime();
while (Utility.getFPGATime() - initTime <= millisecondsToRun){
    // Place your code here.
}
What this does is:
Utility.getFPGATime() gives you a time in milliseconds, say 123400 ms. Now, you want to run your code for a continuous 2 seconds. You would then set the while loop to run your code UNTIL 2 seconds or 2000 ms has passed. So, the loop would be to run until the FPGA time is equals or greater than 125400 ms. And then, it stops running because the conditional is no longer true.
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:30.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi