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

Dependencies:   WakeUp mbed

Committer:
wernert
Date:
Wed Sep 17 09:29:41 2014 +0000
Revision:
1:c0cfd1b0f4ef
Parent:
0:346c8150ca74
Update to disable pull-up that were causing extra current to be drawn.

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 1:c0cfd1b0f4ef 3 #include <stdlib.h>
wernert 1:c0cfd1b0f4ef 4
wernert 1:c0cfd1b0f4ef 5
wernert 1:c0cfd1b0f4ef 6 DigitalIn progMode(P0_3);
wernert 0:346c8150ca74 7
wernert 0:346c8150ca74 8 DigitalOut LED[] = {(P0_7), (P0_8), (P0_2), (P0_20), (P1_19), (P0_17), (P0_23)};// declare 7 LEDs
wernert 0:346c8150ca74 9
wernert 0:346c8150ca74 10 void myDeepSleep() {
wernert 0:346c8150ca74 11 LPC_PMU->PCON = 0x1;
wernert 0:346c8150ca74 12 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
wernert 0:346c8150ca74 13 LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
wernert 0:346c8150ca74 14 __WFI();
wernert 0:346c8150ca74 15 }
wernert 0:346c8150ca74 16
wernert 1:c0cfd1b0f4ef 17
wernert 0:346c8150ca74 18 int main() {
wernert 0:346c8150ca74 19
wernert 0:346c8150ca74 20 int i = 0;
wernert 0:346c8150ca74 21
wernert 1:c0cfd1b0f4ef 22
wernert 1:c0cfd1b0f4ef 23
wernert 1:c0cfd1b0f4ef 24 // Unconfigured GPIO pins default to having the internal pullups enabled.
wernert 1:c0cfd1b0f4ef 25 // The board has a pull down on pin P0_3. This conflict was causing the extra power draw in sleep mode.
wernert 1:c0cfd1b0f4ef 26 // Therefor we disable internal pull-ups to ensure low current mode
wernert 1:c0cfd1b0f4ef 27 progMode.mode(PullNone);
wernert 1:c0cfd1b0f4ef 28
wernert 1:c0cfd1b0f4ef 29
wernert 0:346c8150ca74 30 //The low-power oscillator can be quite inaccurate on some targets
wernert 0:346c8150ca74 31 //this function calibrates it against the main clock
wernert 0:346c8150ca74 32 WakeUp::calibrate();
wernert 0:346c8150ca74 33 while(1)
wernert 0:346c8150ca74 34 {
wernert 0:346c8150ca74 35 LED[i] = 1; // turn on
wernert 1:c0cfd1b0f4ef 36 wait(.05); // delay
wernert 0:346c8150ca74 37 LED[i] = 0; // turn off
wernert 0:346c8150ca74 38
wernert 0:346c8150ca74 39 //Set wakeup time for second
wernert 1:c0cfd1b0f4ef 40 WakeUp::set_ms(5000);
wernert 0:346c8150ca74 41 //Enter deepsleep, the program won't go beyond this point until it is woken up
wernert 0:346c8150ca74 42 myDeepSleep();
wernert 0:346c8150ca74 43 i++;
wernert 0:346c8150ca74 44 if (i >= 7)
wernert 0:346c8150ca74 45 i = 0;
wernert 0:346c8150ca74 46 }
wernert 0:346c8150ca74 47 }