加速度を100HzでSDに保存するプログラム

Dependencies:   MPU6050 SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
oichan
Date:
Sun Dec 24 10:47:14 2017 +0000
Parent:
1:e4d7342be507
Commit message:
SD 100Hz for LPC1768

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	Sun Dec 24 10:47:14 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MPU6050/#5c63e20c50f3
--- a/main.cpp	Tue May 16 05:18:55 2017 +0000
+++ b/main.cpp	Sun Dec 24 10:47:14 2017 +0000
@@ -1,19 +1,44 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
- 
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
- 
-int main() {
-    printf("Hello World!\n");   
- 
+#include "MPU6050.h"
+
+#define RATE        100    //サンプリングレート[Hz]
+#define SAVE_NUM    100     //一度に保存するデータ数   SAVE_NUM/RATE [s]ごとに保存する
+
+SDFileSystem    sd(p11, p12, p13, p14, "sd");
+MPU6050         mpu(p9,p10);
+Timer           jikan;
+Ticker          get_t;
+Serial          pc(USBTX,USBRX);
+FILE            *bp;
+
+void _getData();
+
+float   Data[2][SAVE_NUM][4]={0};
+int     Data_cnt = 0;
+bool    row;
+
+int main(){
+    pc.printf("Hello!\r\n");
     mkdir("/sd/mydir", 0777);
-    
-    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
+    bp = fopen("/sd/mydir/data.bin","ab");  //ファイルは作成は時間がかかるため先にやる
+    fclose(bp);
+    jikan.start();
+    get_t.attach(&_getData,1.0/RATE);
+    while(1){
+        if(Data_cnt==SAVE_NUM){
+            Data_cnt=0;
+            row = !row;
+            bp = fopen("/sd/mydir/data.bin","ab");
+            fwrite(&Data[!row][0][0],sizeof(float),4*SAVE_NUM,bp);
+            fclose(bp);
+        }
     }
-    fprintf(fp, "Hello fun SD Card World!");
-    fclose(fp); 
- 
-    printf("Goodbye World!\n");
+    return 0;
 }
+
+void _getData(){
+    Data[row][Data_cnt][0] = jikan.read();
+    mpu.getAccelero(&Data[row][Data_cnt][1]);
+    Data_cnt++;
+}
\ No newline at end of file