Low-powered blinky example

Dependencies:   mbed

Blinks an LED using a low-power ticker.

Uses the asynchronous APIs and improved sleep API.

Committer:
stevew817
Date:
Mon Sep 12 08:41:41 2016 +0000
Revision:
4:0bf3fe309b3e
Parent:
3:c950338a014e
Updated mbed library to latest version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stevew817 0:b0927d62ef70 1 #include "mbed.h"
stevew817 0:b0927d62ef70 2
stevew817 0:b0927d62ef70 3 DigitalOut myled(LED1);
stevew817 0:b0927d62ef70 4 LowPowerTicker toggleTicker;
stevew817 0:b0927d62ef70 5
stevew817 3:c950338a014e 6 /**
stevew817 3:c950338a014e 7 * This is a callback! Do not call frequency-dependent operations here.
stevew817 3:c950338a014e 8 *
stevew817 3:c950338a014e 9 * For a more thorough explanation, go here:
stevew817 3:c950338a014e 10 * https://developer.mbed.org/teams/SiliconLabs/wiki/Using-the-improved-mbed-sleep-API#mixing-sleep-with-synchronous-code
stevew817 3:c950338a014e 11 **/
stevew817 0:b0927d62ef70 12 void ledToggler(void) {
stevew817 0:b0927d62ef70 13 myled = !myled;
stevew817 0:b0927d62ef70 14 }
stevew817 0:b0927d62ef70 15
stevew817 0:b0927d62ef70 16 int main() {
stevew817 0:b0927d62ef70 17 toggleTicker.attach(&ledToggler, 0.2f);
stevew817 0:b0927d62ef70 18 while(1) {
stevew817 0:b0927d62ef70 19 sleep();
stevew817 0:b0927d62ef70 20 }
stevew817 0:b0927d62ef70 21 }