test

Dependencies:   mbed MMA8452Q

Fork of HelloWorld by Simon Ford

Revision:
9:f36f1506a840
Parent:
8:bb27936d2358
Child:
10:386a3a12f3cf
diff -r bb27936d2358 -r f36f1506a840 main.cpp
--- a/main.cpp	Wed Aug 30 20:01:44 2017 +0000
+++ b/main.cpp	Wed Aug 30 20:09:39 2017 +0000
@@ -1,20 +1,24 @@
 #include "mbed.h"    
+#include "MMA8452Q.h"
 
           
  //hello
 Serial pc(USBTX, USBRX); // tx, rx
-I2C comI2C(p9,p10); // sda, scl
+//I2C comI2C(p9,p10); // sda, scl
 // Communication I2C
 int main() {
     
-    comI2C.start();
-    comI2C.write(0x1D);  // A write to device
-    comI2C.write(0x06); // Register to read from (acceleration in X)
-    comI2C.start();        // Need to send start condition here
-    comI2C.write(0x1D); // tell devide you want to read
-    int c=comI2C.read(0);      // Read the data with NACK
-    comI2C.stop();
-    pc.printf("degree : %d", c);
+     float x, y, z ;
+ 
+     MMA8452Q acc(p9,p10,0x1d);
+ 
+     while (true) {       
+         x = acc.getAccX() ;
+         y = acc.getAccY() ;
+         z = acc.getAccZ() ;
+         printf("X[%.2f] Y[%.2f] Z[%.2f]\n",x, y, z) ;
+         wait(0.1);
+         }
 }