ROBOTC.net forums
http://www.robotc.net/forums/

time1(T1)
http://www.robotc.net/forums/viewtopic.php?f=11&t=3350
Page 1 of 1

Author:  mrski [ Mon Jun 27, 2011 6:09 pm ]
Post subject:  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?

Author:  magicode [ Mon Jun 27, 2011 7:48 pm ]
Post subject:  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.

Author:  mrski [ Tue Jun 28, 2011 9:38 am ]
Post subject:  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;
}

Author:  mrski [ Tue Jun 28, 2011 9:38 am ]
Post subject:  Re: time1(T1)

The time is fairly short, easily under 30secs....

Author:  mrski [ Tue Jun 28, 2011 9:59 am ]
Post subject:  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;

}

Author:  mrski [ Tue Jun 28, 2011 10:50 am ]
Post subject:  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);

}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/