Using on board MMA8451Q on FRK25

Dependencies:   MMA8451Q mbed

Files at this revision

API Documentation at this revision

Comitter:
mconti
Date:
Tue Feb 04 08:59:38 2014 +0000
Parent:
5:79a16c0a88c1
Commit message:
Primo commit;

Changed in this revision

MMA8451Q.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
diff -r 79a16c0a88c1 -r 71e35394bb3e MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Tue Feb 04 08:59:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JoKer/code/MMA8451Q/#2d14600116fc
diff -r 79a16c0a88c1 -r 71e35394bb3e main.cpp
--- a/main.cpp	Tue Feb 19 23:49:45 2013 +0000
+++ b/main.cpp	Tue Feb 04 08:59:38 2014 +0000
@@ -1,19 +1,42 @@
 #include "mbed.h"
+#include "MMA8451Q.h"
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+#define ON  0
+#define OFF !ON
+
+//Setup the interrupts for the MMA8451Q
+InterruptIn accInt1(PTA14);
+InterruptIn accInt2(PTA15);//not used in this prog but this is the other int from the accelorometer
+
+uint8_t togstat=0;//Led status
+DigitalOut bled(LED_BLUE);
+
+void tapTrue(void){
+    printf( "-%d\r\n", togstat );
+    togstat = !togstat;
+    
+    if(togstat)
+        bled = 0;
+    else
+        bled=1;    
+}
+
 
 Ticker tick;
 DigitalOut led1(LED_RED);
 DigitalOut led2(LED_GREEN);
 
-void flip() {
-    led2 = !led2;
-}
+int main() {
+        
+    // Accelerometer 
+    MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+    acc.setDoubleTap();//Setup the MMA8451Q to look for a double Tap
+    accInt1.rise(&tapTrue);//call tapTrue when an interrupt is generated on PTA14
 
-int main() {
-    tick.attach(&flip, 0.7); // setup ticker to call flip led2 after 0.7 seconds
-
-    // spin in a main loop.
-    while (true) {
-        led1 = !led1;
-        wait (0.3); // flip led1 every 0.3 seconds
+    while(1)
+    {
+        printf("X:%001.2f Y:%001.2f Z:%001.2f\r", acc.getAccX(), acc.getAccY(), acc.getAccZ() ); 
+        wait(0.02);
     }
 }
\ No newline at end of file