Blinking a LED in low power mode (Replacing the active wait() function to a low power wait function).

Dependencies:   mbed

Committer:
jose_23991
Date:
Wed Oct 29 20:53:20 2014 +0000
Revision:
0:f1ecec258a2c
Version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jose_23991 0:f1ecec258a2c 1 #include "mbed.h"
jose_23991 0:f1ecec258a2c 2
jose_23991 0:f1ecec258a2c 3 DigitalOut led(LED1, 0); // Create the LED object and setup OFF
jose_23991 0:f1ecec258a2c 4 Timeout timeout; // Create the Timeout object
jose_23991 0:f1ecec258a2c 5
jose_23991 0:f1ecec258a2c 6 void wait_LowPow(unsigned long time); // Wait in low power mode function prototype
jose_23991 0:f1ecec258a2c 7
jose_23991 0:f1ecec258a2c 8 void timer_interrupt() // The Timer interrupt service routine
jose_23991 0:f1ecec258a2c 9 {
jose_23991 0:f1ecec258a2c 10 // Nothing to do, just for wakeup the system
jose_23991 0:f1ecec258a2c 11 }
jose_23991 0:f1ecec258a2c 12
jose_23991 0:f1ecec258a2c 13 int main()
jose_23991 0:f1ecec258a2c 14 {
jose_23991 0:f1ecec258a2c 15 while(1)
jose_23991 0:f1ecec258a2c 16 {
jose_23991 0:f1ecec258a2c 17 led = 1; // Turn LED ON
jose_23991 0:f1ecec258a2c 18 wait_LowPow(1); // Wait 1s in low power mode
jose_23991 0:f1ecec258a2c 19 led = 0; // Turn LED OFF
jose_23991 0:f1ecec258a2c 20 wait_LowPow(1); // Wait 1s in low power mode
jose_23991 0:f1ecec258a2c 21 }
jose_23991 0:f1ecec258a2c 22 }
jose_23991 0:f1ecec258a2c 23
jose_23991 0:f1ecec258a2c 24 void wait_LowPow(unsigned long time) // Wait in low power mode function implementation
jose_23991 0:f1ecec258a2c 25 {
jose_23991 0:f1ecec258a2c 26 timeout.attach(&timer_interrupt, time); // Set the timer interrupt service rutine (ISR) and the time for the timeout (in seconds)
jose_23991 0:f1ecec258a2c 27 sleep(); // Enter Low Power Mode (It cant be used deep_sleep() mode, because that mode disable the timer)
jose_23991 0:f1ecec258a2c 28 }