Timer

The Timer class, provides by the underlining mbed OS, is used to start, stop and read a timer for measuring small times (between microseconds and seconds). For more information about Timer, please visit MbedOS

Assembly

Arduino.h

Summary

Constructors
Timer - Timer ()
Methods
start - void start()
stop - void stop()
reset - void reset()
read - float read()
read_ms - int read_ms()
read_us - int read_us()

Constructors

Timer

Timer() 

Methods

start

void start()

Start the timer

stop

void stop()

Stop the timer

reset

void reset()

Reset the timer to 0.

read

float read()

Get the time passed in seconds.

Return value

Time passed in seconds.

read_ms

int read_ms()

Get the time passed in milli-seconds.

Return value

Time passed in milli seconds.

read_us

int read_us()

Get the time passed in micro-seconds.

Return value

Time passed in milli seconds.

Sample code


Timer t;

void setup() {
    pinMode(LED_USER, OUTPUT);
}

void loop() {
    t.start();
    digitalWrite(LED_USER, HIGH);       
    delay(100); 
    digitalWrite(LED_USER, LOW); 
    delay(100); 
    t.stop();
    Serial.printf("The time taken was %f seconds\r\n", t.read());
    Serial.printf("The time taken was %d milli seconds\r\n", t.read_ms());
    Serial.printf("The time taken was %d micro seconds\r\n", t.read_us());
    t.reset();
    delay(1000);
}