(多分)全部+フライトピン+新しい加速度

Dependencies:   mbed

Revision:
8:d41f5d7d2aa5
Parent:
6:574d9a6253c7
Child:
9:fb19a93df88f
--- a/main.cpp	Mon Oct 22 02:30:19 2018 +0000
+++ b/main.cpp	Wed Oct 24 09:08:53 2018 +0000
@@ -3,8 +3,11 @@
 #include "ultrasonic.h"
 #include "motordriver.h"
 #include "HMC5883L.h"
+#include "MPU6050.h"
 
-Serial pc(USBTX, USBRX);            //地磁気センサー
+MPU6050 mpu(p9,p10);//(SDA,SCL)のピンをアサインしてね☆   加速度センサー
+
+Serial pc(USBTX, USBRX);            //地磁気センサー,GPS
 HMC5883L compass(p28, p27);
 
 DigitalOut FET(p21);                //FET
@@ -15,8 +18,7 @@
                                     //何もないつまりスリットの部分ではローの0を返す。それを変数testに代入している
 DigitalIn test2(p18);
 
-Serial pc(USBTX, USBRX);            //GPS
-GPS gps(p28, p27); 
+GPS gps(p28, p27);                  //GPS
 
 Motor motor1(p22, p16, p17, 1); // pwm, fwd, rev, can brake     モーター
 Motor motor2(p22, p19, p20, 1); // pwm, fwd, rev, can brake
@@ -66,9 +68,12 @@
 
     }    
     fprintf(fp,"GPS finish\r\n");
-    fclose(fp);                      //GPSの測定終了  
+    fclose(fp);                      //GPSの測定終了 
+     
     
     compass.init();                  //地磁気センサー動作
+    pc.printf("raw=%f\r\n",compass.getHeadingXYDeg()); /*度数法で表記*/ 
+    
   
         mu.startUpdates();//start mesuring the distance(超音波センサー)
         int distance; 
@@ -85,9 +90,16 @@
     {       
         distance=mu.getCurrentDistance();   
         printf("%d\r\n",distance); 
+        
+        float accel[3];//accelを3つの配列で定義。         加速度センサー
+        mpu.readAccelData(accel);//加速度の値をaccel[3]に代入
+        float x = accel[0]/16384;//x軸方向の加速度
+        float y = accel[1]/16384;//y軸方向の加速度
+        float z = accel[2]/16384;//z軸方向の加速度
+        printf("accel x:%f y:%f z:%f\r\n",x,y,z);//一応表示しとくやで~~
     
     
-        printf("%d\r\n", test.read());
+        printf("%d\r\n", test.read());              //フォトインタラプタ
         printf("%d\r\n", test2.read());
         if (test.read() == 1 and flag == 0){        //もしtestが1つまり何か障害物があって、かつflagが0つまりスイッチが切れているときは
             flag = 1;                               //この時はスイッチを1に切る。ただ障害物があるかつスイッチが1で切れているときはそのまま