HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
hololib::Timer Class Reference

#include <Timer.hpp>

Public Member Functions

 Timer (uint32_t time)
 Construct a new Timer.
 
uint32_t getTimeSet ()
 Get the amount of time the timer was set to.
 
uint32_t getTimeLeft ()
 Get the amount of time left on the timer.
 
uint32_t getTimePassed ()
 Get the amount of time passed on the timer.
 
bool isDone ()
 Get whether the timer is done or not.
 
bool isPaused ()
 Get whether the timer is paused or not.
 
void set (uint32_t time)
 Set the amount of time the timer should count down.
 
void reset ()
 reset the timer
 
void pause ()
 pause the timer
 
void resume ()
 resume the timer
 
void waitUntilDone ()
 wait until the timer is done
 

Detailed Description

Definition at line 5 of file Timer.hpp.

Constructor & Destructor Documentation

◆ Timer()

hololib::Timer::Timer ( uint32_t  time)

Construct a new Timer.

Note
the timer will start counting down as soon as it is created
the timer constructor is non-blocking so code after it will be executed immediately
if the timer is constructed in a global scope, its behavior is undefined. You can call set() before using the timer if you absolutely need to construct it in a global scope
Parameters
timehow long to wait

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);

Member Function Documentation

◆ getTimeSet()

uint32_t hololib::Timer::getTimeSet ( )

Get the amount of time the timer was set to.

Returns
Time time

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// get the time the timer was set to
const Time time = timer.getTimeSet(); // time = 1_sec

◆ getTimeLeft()

uint32_t hololib::Timer::getTimeLeft ( )

Get the amount of time left on the timer.

Returns
Time time

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// delay for 300ms
pros::delay(300);
// get the time left on the timer
const Time time = timer.getTimeLeft(); // time = 700_msec

◆ getTimePassed()

uint32_t hololib::Timer::getTimePassed ( )

Get the amount of time passed on the timer.

Returns
Time time

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// delay for 300ms
pros::delay(300);
// get the time passed on the timer
const Time time = timer.getTimePassed(); // time = 300_msec

◆ isDone()

bool hololib::Timer::isDone ( )

Get whether the timer is done or not.

Returns
true the timer is done
false the timer is not done

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// delay for 500ms
pros::delay(500);
// check if the timer is done
const bool done = timer.isDone(); // done = false
// delay for another 500ms
pros::delay(500);
// check if the timer is done
const bool done = timer.isDone(); // done = true

◆ isPaused()

bool hololib::Timer::isPaused ( )

Get whether the timer is paused or not.

Returns
true the timer is paused
false the timer is not paused

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// pause the timer
timer.pause();
// check if the timer is paused
bool paused = timer.isPaused(); // paused = true
// resume the timer
timer.resume();
// check if the timer is paused
paused = timer.isPaused(); // paused = false

◆ set()

void hololib::Timer::set ( uint32_t  time)

Set the amount of time the timer should count down.

Resets the timer

Parameters
timetime in milliseconds

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// set the timer to wait for 2 seconds
timer.set(2_sec);

◆ reset()

void hololib::Timer::reset ( )

reset the timer

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// delay for 500ms
pros::delay(500);
// reset the timer
timer.reset();
// delay for another 500ms
pros::delay(500);
// check if the timer is done
const bool done = timer.isDone(); // done = false

◆ pause()

void hololib::Timer::pause ( )

pause the timer

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// pause the timer
timer.pause();
// delay for 2000ms
pros::delay(2000);
// check if the timer is done
const bool done = timer.isDone(); // done = false

◆ resume()

void hololib::Timer::resume ( )

resume the timer

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// pause the timer
timer.pause();
// delay for 500ms
pros::delay(500);
// resume the timer
timer.resume();
// delay for another 500ms
pros::delay(500);
// check if the timer is done
const bool done = timer.isDone(); // done = false

◆ waitUntilDone()

void hololib::Timer::waitUntilDone ( )

wait until the timer is done

Example

// create a timer that will wait for 1 second
Timer timer(1_sec);
// wait until the timer is done
timer.waitUntilDone();
std::cout << "done!" << std::endl;