api / mbed / trunk / Timer

Timer

class Timer : public Base

A general purpose timer

Example

// Count the time to toggle a LED

#include "mbed.h"

Timer timer;
DigitalOut led(LED1);
int begin, end;

int main() {
    timer.start();
    begin = timer.read_us();
    led = !led;
    end = timer.read_us();
    printf("Toggle the led takes %d us", end - begin);
}
TimerA general purpose timer
Functions
startStart the timer
stopStop the timer
resetReset the timer to 0.
readGet the time passed in seconds
read_msGet the time passed in mili-seconds
read_usGet the time passed in micro-seconds

Functions

start

void start()

Start the timer

stop

void stop()

Stop the timer

reset

void reset()

Reset the timer to 0.

If it was already counting, it will continue

read

float read()

Get the time passed in seconds

read_ms

int read_ms()

Get the time passed in mili-seconds

read_us

int read_us()

Get the time passed in micro-seconds

class Timer : public Base
A general purpose timer
void start()
Start the timer
void stop()
Stop the timer
void reset()
Reset the timer to 0.
float read()
Get the time passed in seconds
int read_ms()
Get the time passed in mili-seconds
int read_us()
Get the time passed in micro-seconds