Sample for MPU6050 (used by Nucleo-STMF303K8)

Dependencies:   MPU6050 mbed

Files at this revision

API Documentation at this revision

Comitter:
mikawataru
Date:
Tue Feb 21 14:30:40 2017 +0000
Parent:
0:83aeb4287ca7
Commit message:
????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 83aeb4287ca7 -r e24f8a7fc545 main.cpp
--- a/main.cpp	Fri Jun 17 15:14:59 2016 +0000
+++ b/main.cpp	Tue Feb 21 14:30:40 2017 +0000
@@ -1,10 +1,8 @@
 #include "mbed.h"
 #include "MPU6050.h"
-#define acc 16384
-#define gyro 131
 
 DigitalOut myled(LED1);
-MPU6050 mpu(D4,D5);
+MPU6050 mpu(p9,p10);
 Serial pc(USBTX, USBRX);
 
 int main() {
@@ -17,12 +15,8 @@
         wait(0.2);
         myled = 0;
         wait(0.2);
-        a[0] = (float)mpu.getAcceleroRawX()/acc;
-        a[1] = (float)mpu.getAcceleroRawY()/acc;
-        a[2] = (float)mpu.getAcceleroRawZ()/acc;
-        g[0] = (float)mpu.getGyroRawX()/gyro;
-        g[1] = (float)mpu.getGyroRawY()/gyro;
-        g[2] = (float)mpu.getGyroRawZ()/gyro;
-        pc.printf("%f,%f,%f,%f,%f,%f\n",a[0],a[1],a[2],g[0],g[1],g[2]);
+        mpu.getAccelero(a);
+        mpu.getGyro(g);
+        pc.printf("%4.3f,%4.3f,%4.3f,%4.3f,%4.3f,%4.3f\r\n",a[0],a[1],a[2],g[0],g[1],g[2]);
     }
 }