Skip to content

getStopwatch

gicking edited this page Feb 6, 2018 · 4 revisions

back to Command Reference / Time

Description

Returns the milliseconds since one of several stopwatches was started. Stopwatches are started via startStopwatch(). The number of different stopwatches is NUM_STOPWATCH=5 by default. Different values can be set via config.h.

Notes:

  • stopwatches are based on the 1ms clock, and therefore require the TIM4 interrupt to be active. For details refer to decription of millis().
  • automatic scheduling in background, i.e. without polling, is easily done by combining stopwatches and attachInterruptMillis()

Inclusion

  • defined in stopwatch.h
  • not loaded by main_general.h
  • in config.h set #define USE_TIM4_UPD_ISR for time-keeping functions (see millis()).
  • for different numbers of stopwatches, add #define NUM_STOPWATCH newVal in config.h

Syntax

getStopwatch(n)

Parameters

  • input:

    • n: index of stopwatch to read (0..NUM_STOPWATCH-1)
  • output:

    • none

Returns

Example Code

The below code realizes a (very) simple scheduler using a a stopwatch.

#include "main_general.h"
#include "stopwatch.h"

void setup() {
  pinMode(&PORT_D, 0, OUTPUT);
  startStopwatch(0);
}

void loop() {
  if (getStopwatch(0) >= 123) {
    startStopwatch(0);
    pinOutputReg(&PORT_D, pin0) ^= 1;
  }
}

Relevant Tutorial

  • tbd

See also

Clone this wiki locally