ENSMM / Mbed 2 deprecated TIMER

Dependencies:   mbed

Fork of TIMER by Joël Imbaud

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Main.cpp Source File

Main.cpp

00001 /* https://os.mbed.com/docs/v5.7/reference/timer.html
00002 
00003 Use the Timer interface to create, start, stop and read a timer for measuring small times (between microseconds and seconds). 
00004 You can independently create, start and stop any number of Timer objects.
00005 */
00006 
00007 // Count the time to toggle a LED
00008 
00009 #include "mbed.h"
00010 
00011 Timer timer;
00012 DigitalOut led(LED1);
00013 int begin, end;
00014 
00015 int main() {
00016 
00017     while(1) {
00018                 timer.start();
00019                 begin = timer.read_us();
00020                 led = !led;
00021                 end = timer.read_us();
00022                 printf("Toggle the led takes %d us \n", end - begin);
00023                 wait(1);
00024              }
00025            }