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:
- 5:1fe35a74799a
- Parent:
- 4:ba9ca0a0f87e
- Child:
- 6:825780dcf426
diff -r ba9ca0a0f87e -r 1fe35a74799a main.cpp
--- a/main.cpp Mon Feb 09 20:05:43 2015 +0000
+++ b/main.cpp Mon Feb 16 18:18:34 2015 +0000
@@ -15,12 +15,18 @@
#define REG_OUT_X_MSB 0x01
#define REG_OUT_Y_MSB 0x03
#define REG_OUT_Z_MSB 0x05
+#define REG_PULSE_CFG 0x21
#define REG_PULSE_SRC 0x22
-#define REG_PULSE_CFG 0x21
+#define REG_PULSE_THSZ 0x25
+#define REG_CTRL_4 0x2D
+#define REG_CTRL_5 0x2E
#define MAX_2G 0x00
#define MAX_4G 0x01
#define MAX_8G 0x02
+#define SET_INTERRUPT 0x08
+#define SET_INT_LINE 0x08
+
//#define PRINTDBUG
// Accelerometer SPI pins
@@ -37,7 +43,8 @@
#define MMA8451_I2C_ADDRESS (0x1d<<1)
Ticker ledBlink; // timinginterrupt for RED led
-InterruptIn mybutton(PTC3); //push botton with internal pullup
+//InterruptIn mybutton(PTC3); //push botton with internal pullup
+InterruptIn MMA8451QInt1(PTC5); //push botton with internal pullup
DigitalOut myled(LED_RED); // red led
DigitalOut relay(LED_GREEN); // green led
@@ -67,29 +74,33 @@
outState = !outState;
myled.write(outState);
}
-
-
-void pressed() // button intterupt
-{
- relayState = !relayState;
+
+void GreenLEDBlinker(){ // Green LED interrupt
+ relayState = !relayState;
relay.write(relayState);
}
+
int main()
{
uint8_t regData = MAX_4G;
uint8_t latchData = 0x40; //0b01000000; //for pulse config register
uint8_t axisData = 0x10; //0b00010000;
+ uint8_t interrupt1Data = 0x08; //0b00001000;
+ uint8_t interrupt2Data = 0x04; //0b00000100;
char lcdData[LCDLEN];
myled.write(outState);
relay.write(relayState);
// set up interrrupts to be used later for taps
- mybutton.fall(&pressed);
+ MMA8451QInt1.rise(&GreenLEDBlinker);
+ MMA8451QInt1.mode(PullNone);
+
// set up interrrupts to be used later for taps
+// mybutton.fall(&pressed);
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);
@@ -99,6 +110,13 @@
sprintf (lcdData,"%x",regData);
LCDMess(lcdData,BLINKTIME);
+
+// Set up (pulse) interrupt to INT1 pin
+ regData = interrupt1Data;
+ acc.setRegisterInStandby(REG_CTRL_4, regData); // write the data
+ regData = interrupt2Data;
+ acc.setRegisterInStandby(REG_CTRL_5, regData); // write the data
+
while (true) {
// Read Pulse Source Data and check to see if things have been set
@@ -111,12 +129,12 @@
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);
+ LCDMess(lcdData,BLINKTIME);
LCDMessNoDwell(LCDMessages[relayState]);
wait(delay);
}
-}
+}
\ No newline at end of file