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

Dependencies:   WakeUp mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "WakeUp.h"
00003 #include <stdlib.h>
00004 
00005 
00006 DigitalIn progMode(P0_3);
00007 
00008 DigitalOut LED[] = {(P0_7), (P0_8), (P0_2), (P0_20), (P1_19), (P0_17), (P0_23)};// declare 7 LEDs
00009 
00010 void myDeepSleep() {
00011     LPC_PMU->PCON = 0x1;
00012     SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
00013     LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
00014     __WFI();
00015 }
00016 
00017 
00018 int main() {
00019 
00020     int i = 0;
00021     
00022     
00023     
00024     // Unconfigured GPIO pins default to having the internal pullups enabled. 
00025     // The board has a pull down on pin P0_3. This conflict was causing the extra power draw in sleep mode.
00026     // Therefor we disable internal pull-ups to ensure low current mode
00027     progMode.mode(PullNone);
00028 
00029     
00030     //The low-power oscillator can be quite inaccurate on some targets
00031     //this function calibrates it against the main clock
00032     WakeUp::calibrate();
00033     while(1)
00034     {  
00035         LED[i] = 1; // turn on
00036         wait(.05);   // delay
00037         LED[i] = 0; // turn off
00038         
00039          //Set wakeup time for second
00040         WakeUp::set_ms(5000);
00041         //Enter deepsleep, the program won't go beyond this point until it is woken up
00042         myDeepSleep();
00043         i++;
00044         if (i >= 7) 
00045            i = 0;             
00046     }
00047 }