Low-powered blinky example

Dependencies:   mbed

Blinks an LED using a low-power ticker.

Uses the asynchronous APIs and improved sleep API.

Information

All examples in this repo are considered EXPERIMENTAL QUALITY, meaning this code has been created as one-off proof-of-concept and is suitable as a demonstration for experimental purposes only. This code will not be regularly maintained by Silicon Labs and there is no guarantee that these projects will work across all environments, SDK versions and hardware.

Committer:
stevew817
Date:
Mon Aug 10 07:52:21 2015 +0000
Revision:
3:c950338a014e
Parent:
0:b0927d62ef70
Added note on callback usage

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 }