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
Fork of KL46z_double_tap_2017 by
Revision 3:53d47a5dbb2c, committed 2015-02-03
- Comitter:
- scohennm
- Date:
- Tue Feb 03 18:05:52 2015 +0000
- Parent:
- 2:17a0550771c4
- Child:
- 4:ba9ca0a0f87e
- Commit message:
- Use for setting single tap
Changed in this revision
| MMA8451Q8.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MMA8451Q8.lib Sun Feb 01 19:26:52 2015 +0000 +++ b/MMA8451Q8.lib Tue Feb 03 18:05:52 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/scohennm/code/MMA8451Q8a/#ed7e11d269f8 +http://developer.mbed.org/users/scohennm/code/MMA8451Q8b/#993bb9e96a4b
--- a/main.cpp Sun Feb 01 19:26:52 2015 +0000
+++ b/main.cpp Tue Feb 03 18:05:52 2015 +0000
@@ -1,29 +1,67 @@
#include "mbed.h"
#include "MMA8451Q8.h"
#include "SLCD.h"
-#define RELAYON 0
-#define RELAYOFF 1
-#define LEDDELAY 0.75
-#define WAITDELAY 3.0
+
+#define BLINKTIME 0.7
+#define RELAYON 0
+#define RELAYOFF 1
+#define LEDDELAY 0.75
+#define WAITDELAY 3.0
+#define LCDLEN 10
+
+#define REG_WHO_AM_I 0x0D
+#define XYZ_DATA_CFG 0x0E
+
+#define REG_OUT_X_MSB 0x01
+#define REG_OUT_Y_MSB 0x03
+#define REG_OUT_Z_MSB 0x05
+#define REG_PULSE_SRC 0x22
+#define REG_PULSE_CFG 0x21
+
+#define MAX_2G 0x00
+#define MAX_4G 0x01
+#define MAX_8G 0x02
+
+//#define PRINTDBUG
+// Accelerometer SPI pins
+#if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
+ PinName const SDA = PTE25;
+ PinName const SCL = PTE24;
+#elif defined (TARGET_KL05Z)
+ PinName const SDA = PTB4;
+ PinName const SCL = PTB3;
+#else
+ #error TARGET NOT DEFINED
+#endif
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
Ticker ledBlink; // timinginterrupt for RED led
InterruptIn mybutton(PTC3); //push botton with internal pullup
DigitalOut myled(LED_RED); // red led
DigitalOut relay(LED_GREEN); // green led
+ MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
float delay = WAITDELAY;
int relayState = RELAYOFF;
int outState = false;
SLCD slcd; //define LCD display
-char LCDMessages[2][10] = {"TRUE", "FALS"};
+char LCDMessages[2][LCDLEN] = {"TRUE", "FALS"};
-void LCDMess(char *lMess){
- slcd.Home();// message stays till next update
+void LCDMess(char *lMess, float dWait){
+ slcd.Home();
slcd.clear();
slcd.printf(lMess);
-}
+ wait(dWait);
+}
+void LCDMessNoDwell(char *lMess){
+ slcd.Home();
+ slcd.clear();
+ slcd.printf(lMess);
+}
+
void LEDBlinker(){ // RED LED interrupt
outState = !outState;
@@ -39,13 +77,45 @@
int main()
{
+ uint8_t regData = MAX_4G;
+ uint8_t latchData = 0x40; //0b01000000; //for pulse config register
+ uint8_t axisData = 0x10; //0b00010000;
+ char lcdData[LCDLEN];
+
myled.write(outState);
relay.write(relayState);
+
+// set up interrrupts to be used later for taps
mybutton.fall(&pressed);
+// set up interrrupts to be used later for taps
ledBlink.attach(&LEDBlinker, LEDDELAY);
+
+// Check to see if accerlometer is alive and well
+ acc.setGLimit(MAX_2G); // For now set to 2g
+ acc.readRegs(XYZ_DATA_CFG, ®Data, 1);
+ sprintf (lcdData,"%x",regData); // Note displaying in hexidecimal
+ LCDMess(lcdData,BLINKTIME);
+ acc.readRegs(REG_WHO_AM_I, ®Data, 1);
+ sprintf (lcdData,"%x",regData);
+ LCDMess(lcdData,BLINKTIME);
+
while (true) {
- // other things can be put here.
- LCDMess(LCDMessages[relayState]);
+
+ // 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);
+
+ acc.setPulseConfiguration(latchData, axisData); // write the data
+ acc.readRegs(REG_PULSE_CFG, ®Data, 1); // check it
+ sprintf (lcdData,"%x",regData);
+ LCDMess(lcdData,BLINKTIME);
+
+ acc.readRegs(REG_PULSE_SRC, ®Data, 1);
+ sprintf (lcdData,"%x",regData);
+ LCDMess(lcdData,BLINKTIME);
+
+ LCDMessNoDwell(LCDMessages[relayState]);
wait(delay);
}
}
