Basic example of how to blink a led using the Ticker object.

Dependencies:   mbed

Committer:
arostm
Date:
Wed Jun 07 14:11:17 2017 +0000
Revision:
1:7773a5ce9853
Parent:
0:57e0a19da71e
Adding new mbed library

Who changed what in which revision?

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