Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8451Q8b SLCD mbed
Diff: main.cpp
- Revision:
- 10:c7ac4fd52536
- Parent:
- 9:08acb96591a8
--- a/main.cpp Mon Feb 16 20:06:22 2015 +0000 +++ b/main.cpp Wed Feb 18 15:08:07 2015 +0000 @@ -2,10 +2,10 @@ #include "MMA8451Q8g.h" #include "SLCD.h" -#define BLINKTIME 0.7 +#define BLINKTIME 0.2 #define RELAYON 0 #define RELAYOFF 1 -#define LEDDELAY 0.75 +#define LEDDELAY 0.4 #define WAITDELAY 0.7 #define LCDLEN 10 @@ -18,6 +18,7 @@ #define REG_PULSE_CFG 0x21 #define REG_PULSE_SRC 0x22 #define REG_PULSE_THSZ 0x25 +#define REH_PULSE_TMLT 0x25 #define REG_CTRL_4 0x2D #define REG_CTRL_5 0x2E @@ -26,7 +27,8 @@ #define MAX_8G 0x02 #define SET_INTERRUPT 0x08 #define SET_INT_LINE 0x08 - +#define SET_THZ 0x20 // See Table 49 in data sheet +#define SET_TMLT 0x18 // See Talbe 51 in data sheet //#define PRINTDBUG // Accelerometer SPI pins @@ -69,21 +71,24 @@ slcd.printf(lMess); } - +// Interrupt routines void LEDBlinker(){ // RED LED interrupt outState = !outState; myled.write(outState); } void GreenLEDBlinker(){ // Green LED interrupt + //uint8_t i_regData; relayState = !relayState; relay.write(relayState); -} - + //acc.readRegs(REG_PULSE_SRC, &i_regData, 1); // Clear the tap event +} + +// end interrupt routines int main() { - uint8_t regData = MAX_4G; + uint8_t regData; uint8_t latchData = 0x40; //0b01000000; //for pulse config register uint8_t axisData = 0x10; //0b00010000; @@ -97,43 +102,44 @@ MMA8451QInt1.mode(PullNone); // set up interrrupts to be used later for taps -// mybutton.fall(&pressed); ledBlink.attach(&LEDBlinker, LEDDELAY); - + +// Read Pulse Source Data and check to see if things have been set + acc.readRegs(REG_PULSE_CFG, ®Data, 1); // check it + sprintf (lcdData,"%x",regData); + LCDMess(lcdData,BLINKTIME); + +// *********** Initialize for tap tecognition *********** + regData = latchData | axisData; + acc.setRegisterInStandby(REG_PULSE_CFG, regData); // write the data + acc.readRegs(REG_PULSE_CFG, ®Data, 1); // check it + sprintf (lcdData,"%x",regData); + LCDMess(lcdData,BLINKTIME); + // Check to see if accerlometer is alive and well - acc.setGLimit(MAX_2G); // For now set to 2g + acc.setGLimit(MAX_4G); // For now set to 2g acc.readRegs(XYZ_DATA_CFG, ®Data, 1); sprintf (lcdData,"%x",regData); // Note displaying in hexidecimal LCDMess(lcdData,BLINKTIME); +// Setup single-tap pulse prarameters. + acc.setRegisterInStandby(REG_PULSE_THSZ, SET_THZ); // write the data + acc.setRegisterInStandby(REH_PULSE_TMLT, SET_TMLT); // write the data + // Set up (pulse) interrupt to INT1 pin acc.setRegisterInStandby(REG_CTRL_4, SET_INTERRUPT); // write the data acc.setRegisterInStandby(REG_CTRL_5, SET_INT_LINE); // write the data - +// End or seetup + acc.readRegs(REG_WHO_AM_I, ®Data, 1); sprintf (lcdData,"%x",regData); LCDMess(lcdData,BLINKTIME); - + while (true) { - - // Read Pulse Source Data and check to see if things have been set - acc.readRegs(REG_PULSE_CFG, ®Data, 1); // check it - sprintf (lcdData,"%x",regData); - LCDMess(lcdData,BLINKTIME); - - regData = latchData | axisData; - acc.setRegisterInStandby(REG_PULSE_CFG, regData); // write the data - acc.readRegs(REG_PULSE_CFG, ®Data, 1); // check it - if (regData == 0xC0 || regData == 0xC4) - //z-axis event detected - sprintf (lcdData,"%x",regData); - LCDMess(lcdData,BLINKTIME); - acc.readRegs(REG_PULSE_SRC, ®Data, 1); sprintf (lcdData,"%x",regData); - LCDMess(lcdData,BLINKTIME); - + LCDMess(lcdData,BLINKTIME); LCDMessNoDwell(LCDMessages[relayState]); wait(delay); }