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
00001 /* 00002 * LPC1114_5110_PIR 00003 * 00004 * Created on: Dec 26, 2014 00005 * Author: bundgus 00006 * 00007 * Demonstrates the use of the LPC1114_Deep_Power_Down library with the NOKIA_5110 library 00008 */ 00009 00010 #include "mbed.h" 00011 #include "DeepPowerDown.h" 00012 #include "NOKIA_5110.h" 00013 #include <string> 00014 00015 #define startup_countdown 10 00016 00017 // high-level hardware interfaces 00018 DeepPowerDown pd; 00019 DigitalOut backlight(dp18, 0); 00020 LcdPins myLcdPins = { dp2, NC, dp6, dp26, dp25, dp24 }; // mosi, miso, sclk, dc, sce, rst 00021 NokiaLcd myLcd( myLcdPins ); 00022 AnalogIn vref(dp9); 00023 AnalogIn vbat(dp10); 00024 DigitalIn personPIR(dp11); 00025 00026 void startup() 00027 { 00028 // Turn off LCD Backlight 00029 backlight = 0; 00030 00031 // Start the LCD 00032 myLcd.InitLcd(); 00033 myLcd.ClearLcdMem(); 00034 } 00035 00036 void shutdown() 00037 { 00038 myLcd.ShutdownLcd(); 00039 backlight = 0; 00040 pd.powerDown(); 00041 } 00042 00043 void s_firstRun() 00044 { 00045 pd.setGPREG3(1); // set next startup state to motionWake 00046 myLcd.SetXY(0,2); 00047 myLcd.DrawString(" Arming in "); 00048 00049 char cd_c[14]; 00050 00051 for (int cd = startup_countdown; cd>0 ; cd--) { 00052 myLcd.SetXY(0,3); 00053 myLcd.DrawString(" "); 00054 if (cd < 10) { 00055 myLcd.DrawString("0"); 00056 } 00057 sprintf (cd_c, "%ld", cd); 00058 myLcd.DrawString(cd_c); 00059 myLcd.SetXY(0,4); 00060 myLcd.DrawString(" seconds "); 00061 wait_ms(1000); 00062 } 00063 } 00064 00065 void s_motionWake() 00066 { 00067 00068 // check a few times to make sure there isn't a delay with the person PIR after the dog PIR is triggered 00069 int persondetected = 3; 00070 while (persondetected > 0) { 00071 if (personPIR.read() == 1) { 00072 break; 00073 } 00074 wait_ms(500); 00075 persondetected --; 00076 } 00077 00078 myLcd.SetXY(0,0); 00079 if (persondetected > 0) { 00080 myLcd.DrawString(" PERSON"); 00081 pd.setGPREG1(pd.getGPREG1() + 1); 00082 } else { 00083 myLcd.DrawString(" DOG"); 00084 pd.setGPREG0(pd.getGPREG0() + 1); 00085 } 00086 00087 unsigned int dogct = pd.getGPREG0(); 00088 unsigned int personct = pd.getGPREG1(); 00089 00090 myLcd.SetXY(0,1); 00091 myLcd.DrawString(" DETECTED "); 00092 // buffer for gpr 0-4 register string values - 84 columns / 6 columns per char = 14 00093 char gpreg0_c[14]; 00094 00095 sprintf (gpreg0_c, "%ld", dogct); 00096 //myLcd.SetXY(42-((int)log10((float)dogct) + 1)*3,2); 00097 myLcd.SetXY(0,2); 00098 myLcd.DrawString("dog: "); 00099 myLcd.DrawString(gpreg0_c); 00100 00101 sprintf (gpreg0_c, "%ld", personct); 00102 myLcd.SetXY(0,3); 00103 myLcd.DrawString("person: "); 00104 myLcd.DrawString(gpreg0_c); 00105 00106 // analog reading for voltage reference 00107 sprintf (gpreg0_c, "%1.2f", 1.235/vref.read()); 00108 myLcd.SetXY(0,5); 00109 myLcd.DrawString("battery: "); 00110 myLcd.DrawString(gpreg0_c); 00111 myLcd.DrawString("v"); 00112 00113 for (int i=0;i<50;i++){ 00114 if (persondetected == 0) { 00115 backlight = !backlight; 00116 } 00117 wait_ms(100); 00118 } 00119 00120 } 00121 00122 int main(void) 00123 { 00124 unsigned int GPREG3_i = pd.getGPREG3(); // GPREG3 = next application start state 00125 00126 startup(); 00127 00128 switch(GPREG3_i) { 00129 case 0 : 00130 s_firstRun(); 00131 break; 00132 case 1 : 00133 s_motionWake(); 00134 break; 00135 default : /* Optional */ 00136 break;// unknown state 00137 } 00138 00139 shutdown(); 00140 } 00141 00142 00143
Generated on Fri Jul 22 2022 18:06:54 by 1.7.2