View unanswered posts | View active topics It is currently Sun Aug 31, 2014 2:33 am






Reply to topic  [ 6 posts ] 
time1(T1) 
Author Message
Rookie

Joined: Mon Jun 27, 2011 6:05 pm
Posts: 5
Post time1(T1)
Everything I have found so far says if I put this in the program that I can get the value of a timer. I can't find it anywhere. I am trying to make a track timer and have everything perfect except for getting the value at the end of the track. It resets at the beginning but doesn't stop. Is this even possible?


Mon Jun 27, 2011 6:09 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: time1(T1)
I don't know exactly what you're asking, but I can give you some information about the timers.

ROBOTC has 4 timers: T1. T2, T3, and T4. You can access the value of the timer like this:
Code:
time1[T1];//gets the value of timer T1 in milliseconds (1/1000 of a second)
time10[T1];//gets the value of timer T1 in centiseconds (1/100 of a second)
time100[T1];//gets the value of timer T1 in deciseconds (1/10 of a second)
//You can use any of the four timers in place of T1.


You can reset the timer (set it's value to zero and start it) by using ClearTimer(T1); again, you can use any of the four timers.

A word of warning when using timers: the value of the timer will automatically reset and start from zero when the timer's value reaches 32,767. That's about 32.7 seconds if you're counting in milliseconds, so if you want to count times longer than that, you need to account for this "wrap around" in your code.

Hope this helped in what you need to do.

_________________
sudo rm -rf /


Mon Jun 27, 2011 7:48 pm
Profile
Rookie

Joined: Mon Jun 27, 2011 6:05 pm
Posts: 5
Post Re: time1(T1)
Thanks for the response. Your answer is almost there!!! The problem I am having is at the end of this code I need the value of Time1(T1) and it sounds like when RobotC sees this it is suppose to record a time. But I can find it anywhere. And the time in the debug window for T1 just keeps running.... hope this makes more sense.




task main()
{
untilTouch(BumpSwitchStart);
startMotor(port4, -20);
turnFlashlightOn(Flashlightstart,-127);
turnFlashlightOn(flashlightend, -127);
untilDark(275, lightSensorStart);
ClearTimer(T1);
ClearTimer(nClockMinutes);
untilDark(275, lightSenorend);
time1(T1)=1;
}


Tue Jun 28, 2011 9:38 am
Profile
Rookie

Joined: Mon Jun 27, 2011 6:05 pm
Posts: 5
Post Re: time1(T1)
The time is fairly short, easily under 30secs....


Tue Jun 28, 2011 9:38 am
Profile
Rookie

Joined: Mon Jun 27, 2011 6:05 pm
Posts: 5
Post Re: time1(T1)
updated code

this actually somewhat works because at the end it freezes and I can read the time. But is there a correct way of doing this?

task main()
{
untilTouch(BumpSwitchStart);
wait(1);
startMotor(port4, -20);
turnFlashlightOn(Flashlightstart,-127);
turnFlashlightOn(flashlightend, -127);
untilDark(300, lightSensorStart);
ClearTimer(T1);
untilDark(400, lightSenorend);
time1(T1)=1;

}


Tue Jun 28, 2011 9:59 am
Profile
Rookie

Joined: Mon Jun 27, 2011 6:05 pm
Posts: 5
Post Re: time1(T1)
figured it out!!

int race_time;/**/

task main()



{
untilTouch(BumpSwitchStart);
wait(1);
startMotor(port4, -20);
turnFlashlightOn(Flashlightstart,-127);
turnFlashlightOn(flashlightend, -127);
untilDark(300, lightSensorStart);
ClearTimer(T1);
untilDark(400, lightSenorend);
race_time = time1[T1];
writeDebugStreamLine("Time1msec= %d", race_time);
stopMotor(Motor1);
turnFlashlightOff(flashlightend);
turnFlashlightOff(Flashlightstart);

}


Tue Jun 28, 2011 10:50 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.