A

Dependencies:   mbed MPU6050 SDFileSystem

Files at this revision

API Documentation at this revision

Comitter:
kosukesuzuki
Date:
Tue Dec 14 10:55:10 2021 +0000
Parent:
1:e4d7342be507
Commit message:
mpu AND sd

Changed in this revision

MPU6050.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MPU6050.lib	Tue Dec 14 10:55:10 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/cansat-d_2018/code/MPU6050/#51bd76211e3b
--- a/main.cpp	Tue May 16 05:18:55 2017 +0000
+++ b/main.cpp	Tue Dec 14 10:55:10 2021 +0000
@@ -1,19 +1,39 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
+#include "MPU6050.h"
  
 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
- 
+MPU6050 mpu(p9,p10);
+Serial pc(USBTX,USBRX,9600); 
+
+int accel[3];
+
+Timer t;
+
 int main() {
-    printf("Hello World!\n");   
- 
+    t.start();
     mkdir("/sd/mydir", 0777);
-    
     FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
-    fprintf(fp, "Hello fun SD Card World!");
-    fclose(fp); 
+    while(1){
+        mpu.readAccelData(accel);                                                                       //加速度の値をaccel[3]に代入
+        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;
+    
+        pc.printf("%0.4f %.2f %.2f %.2f %.2f\r\n",t.read(),X,Y,Z,a);
+        if(fp == NULL) {
+            error("Could not open file for write\n");
+        }
+        fprintf(fp, "%.2f %.2f %.2f %.2f\r\n",X,Y,Z,a);
+        if(t >= 10){  
+            fclose(fp);
+            t.stop();
+            return 0;
+            }
+            }
  
-    printf("Goodbye World!\n");
 }