Časovač#

Zavedení#

Třída timer se používá k měření času a interakci s časovačem nezávislým na Brainově časovači.

Konstruktor třídy#

timer();

Destruktor tříd#

Zničí objekt časovače timer a uvolní přidružené zdroje.

~timer();

Parametry#

Tento konstruktor nepřijímá žádné parametry.

Příklady#

// Create a timer instance
timer myTimer = timer();

Členské funkce#

Třída timer obsahuje následující členské funkce:

  • reset — Resets the timer to zero.

  • value — Returns the elapsed time since the timer started.

  • event — Volá funkci po zadaném počtu milisekund s volitelnými argumenty.

Před voláním jakékoli členské funkce timer musí být vytvořena instance timer , jak je znázorněno níže:

/* This constructor is required to use a 
custom timer. Replace the values
as needed. */

// Create a timer instance
timer myTimer = timer();

/* This constructor is required when using VS Code.
A Brain is generated automatically at the start of
VEXcode projects. */

// Create the Brain to use Brain.Timer
brain Brain = brain();

reset#

Nastaví časovač na nulu.

Available Functions
void reset();

Parameters

Tato funkce nepřijímá žádné parametry.

Return Values

Tato funkce nevrací hodnotu.

Examples
while (true) {
  // Clear the timer every time the screen is pressed
  if (Brain.Screen.pressing()) {
    myTimer.reset();
  }
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Time: %.2f", myTimer.value());
  wait(50, msec);
}

value#

Vrátí aktuální hodnotu časovače.

Available Functions
double value();

Parameters

Tato funkce nepřijímá žádné parametry.

Return Values

Dvojitá hodnota představující uplynulý čas v sekundách.

Notes
  • Časovač začne odpočítávat, jakmile je sestaven.

  • Calling reset resets the timer value to zero.

Examples
// Display the timer as it ticks up
while (true) {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Time: %.2f", myTimer.value());

  wait(50, msec);
}

event#

Registruje funkci zpětného volání, která se má provést po zadané prodlevě.

Available Functions

1 — Zaregistruje zpětné volání, které se spustí po zadaném zpoždění, a předá zpětnému volání uživatelem definovanou hodnotu.

static void event(
    void (*callback)(void *),
    uint32_t value );

2 — Zaregistruje zpětné volání, které se spustí po zadané prodlevě.

static void event(
    void (*callback)(void),
    uint32_t value );

Parameters

Parametr

Typ

Popis

callback

void (*)(void *)

Funkce, která bude volána po zadané prodlevě a obdrží uživatelem definovaný argument.

callback

void (*)(void)

Funkce, která bude volána po uplynutí zadané prodlevy.

value

uint32_t

Zpoždění v milisekundách před provedením funkce zpětného volání.

Return Values

Tato funkce nevrací hodnotu.

Notes
  • Tato funkce naplánuje jednorázové zpětné volání; neopakuje se automaticky.

  • Funkce zpětného volání musí vrátit void.

  • Více akcí může být naplánováno současně.

Examples

Definujte funkci (mimo int main())

// Create a function to turn the screen orange
void turnOrange() {
  Brain.Screen.clearScreen(orange);
}

Zaregistrujte funkci uvnitř int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  timer myTimer = timer();
  // Call turnOrange after 2 seconds
  myTimer.event(turnOrange, 2000);
}