Demonstrates the use of the LPC1114_Deep_Power_Down library with the NOKIA_5110 library

Dependencies:   LPC1114_Deep_Power_Down NOKIA_5110 mbed

main.cpp

Committer:
bundgus
Date:
2015-01-03
Revision:
0:5459444bb4f0
Child:
1:118bef2666a8

File content as of revision 0:5459444bb4f0:

/*
 *  LPC1114_5110_PIR
 *
 *  Created on: Dec 26, 2014
 *      Author: bundgus
 *	
 *	Demonstrates the use of the LPC1114_Deep_Power_Down library with the NOKIA_5110 library
 */

#include "mbed.h"
#include "DeepPowerDown.h"
#include "NOKIA_5110.h"
#include <string>

#define startup_countdown 5

// high-level hardware interfaces
DeepPowerDown pd;
LcdPins myLcdPins = { dp2, NC, dp6, dp4, dp5, dp1 };  // mosi, miso, sclk, dc, sce, rst
NokiaLcd myLcd( myLcdPins );
DigitalOut backlight(dp14);

void startup(){
	// Turn on LCD Backlight
    backlight = 1;
    
    // Start the LCD
    myLcd.InitLcd();
	myLcd.ClearLcdMem();
}

void shutdown(){
	myLcd.ShutdownLcd();
	backlight = 0;
	pd.powerDown();
}

void s_firstRun(){
	pd.setGPREG4(1); // set next startup state to motionWake
	myLcd.SetXY(0,2);
	myLcd.DrawString("   Arming in  ");
	
	char cd_c[14];
	
	for (int cd = startup_countdown; cd>0 ; cd--){
		myLcd.SetXY(0,3);
		myLcd.DrawString("      ");
		if (cd < 10){
			myLcd.DrawString("0");
			}
		sprintf (cd_c, "%ld", cd);
		myLcd.DrawString(cd_c);
		myLcd.SetXY(0,4);
		myLcd.DrawString("   seconds    ");
		wait_ms(1000);
	}
}

void s_motionWake(){
	myLcd.SetXY(0,0);
	myLcd.DrawString("    MOTION    ");
	myLcd.DrawString("   DETECTED   ");
	// buffer for gpr 0-4 register string values - 84 columns / 6 columns per char = 14
	char gpreg0_c[14];  
	
	unsigned int gpreg0_i = pd.getGPREG0();
	
	sprintf (gpreg0_c, "%ld", gpreg0_i);   
	
	myLcd.SetXY(42-((int)log10((float)gpreg0_i) + 1)*3,2);
	myLcd.DrawString(gpreg0_c);
	
	myLcd.SetXY(0,3);
	myLcd.DrawString("    TIMES     ");
	
	wait_ms(20000);
	pd.setGPREG0(gpreg0_i + 1);

}

int main(void) {
	unsigned int gpreg4_i = pd.getGPREG4();  // gpreg4 = next application start state
	
	startup();
	
	switch(gpreg4_i){
    case 0 :
       s_firstRun();
       break;
    case 1 :
       s_motionWake();
       break;
    default : /* Optional */
       break;// unknown state
	}
	
	shutdown();
}