example of using the ticker object

Dependents:   Nucleo_gyro

Committer:
tulanthoar
Date:
Fri Apr 21 19:38:58 2017 +0000
Revision:
1:ce7493c6a648
Parent:
0:573c02b712fe
change to mbed-os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tulanthoar 0:573c02b712fe 1 #include "mbed.h"
tulanthoar 0:573c02b712fe 2
tulanthoar 0:573c02b712fe 3 Ticker toggle_led_ticker;
tulanthoar 0:573c02b712fe 4
tulanthoar 0:573c02b712fe 5 DigitalOut led1(LED1);
tulanthoar 0:573c02b712fe 6
tulanthoar 0:573c02b712fe 7 void toggle_led() {
tulanthoar 0:573c02b712fe 8 led1 = !led1;
tulanthoar 0:573c02b712fe 9 }
tulanthoar 0:573c02b712fe 10
tulanthoar 0:573c02b712fe 11 int main() {
tulanthoar 0:573c02b712fe 12 // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms)
tulanthoar 0:573c02b712fe 13 toggle_led_ticker.attach(&toggle_led, 0.1);
tulanthoar 0:573c02b712fe 14 while (true) {
tulanthoar 0:573c02b712fe 15 // Do other things...
tulanthoar 0:573c02b712fe 16 }
tulanthoar 0:573c02b712fe 17 }