加速度センサのプログラム第2版です。 (PCに表示、zの値の正負で上下が分かると思います。)

Dependencies:   mbed MPU6050 Math

Revision:
7:8f914ead7fc0
Parent:
6:f1106d9e843c
Child:
8:8ca0c8d10890
--- a/main.cpp	Tue Nov 20 13:51:57 2018 +0000
+++ b/main.cpp	Sat Nov 24 00:01:13 2018 +0000
@@ -16,11 +16,13 @@
         int accel[3];//accelを3つの配列で定義。
     while(1){
         mpu.readAccelData(accel);//加速度の値をaccel[3]に代入
-        int x = accel[0];//x軸方向の加速度
-        int y = accel[1];//y軸方向の加速度
-        int z = accel[2];//z軸方向の加速度
-        float a = x^2+y^2+z^2;
-        printf("%f\r\n",a);
+        int x = accel[0]-123;//x軸方向の加速度
+        int y = accel[1]+60;//y軸方向の加速度
+        int z = accel[2]+1110 ;//z軸方向の加速度
+        float X = x*0.000597964111328125;
+        float Y = y*0.000597964111328125;
+        float Z = z*0.000597964111328125; 
+        double a = X*X+Y*Y+Z*Z-95.982071137936;
         if (a>0){
         a = sqrt(a);
         }
@@ -28,6 +30,7 @@
         a = abs(a);
         a = -sqrt(a);
         }
+        //printf("%lf %f %f %f\r\n",a,X,Y,Z);
         // ローパスフィルター(現在の値 = 係数 * ひとつ前の値 + (1 - 係数) * センサの値)
         lowpassValue = lowpassValue * filterCoefficient + a * (1 - filterCoefficient);
         // ハイパスフィルター(センサの値 - ローパスフィルターの値)//
@@ -43,7 +46,7 @@
 
         //printf(" speed %f difference %f\r\n",speed,difference);//速度と加速度を表示
         //printf("%f,",speed);//速度を表示
-        //printf("speed %f diference %f\r\n",speed,difference);//変位を表示
-        wait(0.5);
+        printf("speed %f diference %f\r\n",speed,difference);//速度と変位を表示
+        wait(0.01);
     }
 }