mBuino low current/ deep sleep LED flasher to be used as key finder.

Dependencies:   WakeUp mbed

Committer:
wernert
Date:
Sat Sep 06 09:30:35 2014 +0000
Revision:
0:346c8150ca74
Child:
1:c0cfd1b0f4ef
This mBuino project demonstrates a low power LED flasher for mBuino that uses deep sleep to achieve low current consumption. It only flashes one LED at a time for 10 mS long every 1 second.  The idea is for keyring flasher that works for long time.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wernert 0:346c8150ca74 1 #include "mbed.h"
wernert 0:346c8150ca74 2 #include "WakeUp.h"
wernert 0:346c8150ca74 3
wernert 0:346c8150ca74 4 DigitalOut LED[] = {(P0_7), (P0_8), (P0_2), (P0_20), (P1_19), (P0_17), (P0_23)};// declare 7 LEDs
wernert 0:346c8150ca74 5
wernert 0:346c8150ca74 6 void myDeepSleep() {
wernert 0:346c8150ca74 7 LPC_PMU->PCON = 0x1;
wernert 0:346c8150ca74 8 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
wernert 0:346c8150ca74 9 LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
wernert 0:346c8150ca74 10 __WFI();
wernert 0:346c8150ca74 11 }
wernert 0:346c8150ca74 12
wernert 0:346c8150ca74 13 int main() {
wernert 0:346c8150ca74 14
wernert 0:346c8150ca74 15 int i = 0;
wernert 0:346c8150ca74 16
wernert 0:346c8150ca74 17 //The low-power oscillator can be quite inaccurate on some targets
wernert 0:346c8150ca74 18 //this function calibrates it against the main clock
wernert 0:346c8150ca74 19 WakeUp::calibrate();
wernert 0:346c8150ca74 20 while(1)
wernert 0:346c8150ca74 21 {
wernert 0:346c8150ca74 22 LED[i] = 1; // turn on
wernert 0:346c8150ca74 23 wait(.01); // delay
wernert 0:346c8150ca74 24 LED[i] = 0; // turn off
wernert 0:346c8150ca74 25
wernert 0:346c8150ca74 26 //Set wakeup time for second
wernert 0:346c8150ca74 27 WakeUp::set_ms(1000);
wernert 0:346c8150ca74 28 //Enter deepsleep, the program won't go beyond this point until it is woken up
wernert 0:346c8150ca74 29 myDeepSleep();
wernert 0:346c8150ca74 30 i++;
wernert 0:346c8150ca74 31 if (i >= 7)
wernert 0:346c8150ca74 32 i = 0;
wernert 0:346c8150ca74 33 }
wernert 0:346c8150ca74 34 }