About timer in V5 Brain

Do we still have 4 timers in V5? In RobotC,we have 4 timers.
I am using Brain.Timer.time which uses ms as my only timer.

One option would be to use Brain.timer as a global timer, and implement multiple “timers” by keeping track of the global time at which each was last “reset”.

Here’s some example code that does that:

/*the global time at which each ‘timer’ was reset: */
double startTimeA, startTimeB; 

/* When you want to “reset” a timer, set the corresponding ‘startTime’ 
variable to the current global time: */
startTimeA = Brain.timer(vex::timeUnits sec);
startTimeB = Brain.timer(vex::timeUnits sec);

/*Then, the current time of each timer is the current global time 
minus its start time: */
while (true){
    double currA = Brain.timer(vex::timeUnits sec) - startTimeA;
    double currB = Brain.timer(vex::timeUnits sec) - startTimeB;

Using this technique, you could have arbitrarily many different “timers”.


There is a Timer class in the V5 API. This would allow you to create new timers so you aren’t limited to just the one. This link goes to the VCS Command Reference which defines the functions in the Timer class

1069B - Argonauts


Is there any way to reset these instances? Or do they always just count up?

clear() method sets to zero.

One nice, and often overlooked, feature of vex::timer is that it can be set to fire an event at a given time in the future.

timer       Timer;

void cb( void *arg ) {
    std::cout << "timer fired sys:" << timer::system() << " timer:" << Timer << "  \n";

    // rearm
    timer().event( cb, 1000 );    
int main()
    // fire in 1 seconds time
    timer().event( cb, 1000 );

you can then rearm in the event handler for a repeating timer event.


wow so much to learn, relearn etc. and I keep forgetting the V5 API doesn’t open well in Firefox my default browser, but I must open it in chrome to navigate things properly.
Thanks @1069B_Argonauts and @jpearman

1 Like

thank u(◔◡◔)
i will use these codes(It means having alotttt code to changeeee)

I will try it later.