出力計の為に作成した。50ms毎に経過時間を取得して1000ms経過したらそれらの値をsdに保存する。しかし現状として6000ms経過するとプログラムが停止する。

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
Joeatsumi
Date:
Sun Sep 03 01:40:21 2017 +0000
Parent:
1:e4d7342be507
Child:
3:e7f77ec41f33
Commit message:
?????50ms???????????????????????????6000ms???????????????????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue May 16 05:18:55 2017 +0000
+++ b/main.cpp	Sun Sep 03 01:40:21 2017 +0000
@@ -1,19 +1,64 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
  
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+//SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+SDFileSystem sd(dp2,dp1,dp6,dp13,"sd");
+Serial pc(dp16,dp15);
+Timer Time ; 
+Ticker sd_write ;
+DigitalOut myled1(LED1);
+//Serial pc(dp16,dp15);
+
+
+int count =0;//最初はTimeLog[0]から始まる
+
+static unsigned long TimeLog[20];//20個の要素を「箱」を用意する
+unsigned long nowTime = 0;
+   
+    void SD(){//この関数を0.05秒ごとに呼び出して、その度に経過時間をTimeLog[]に代入する。
+              //つまり、50ms毎の時間が配列に保存される。
+              //1000ms経過するとそれらの値をまとめてsdカードに保存する。
+        
+    __disable_irq();//この関数を最優先に割り込みする。
+     myled1 = 0 ;
+     
+      if(count<19){
+              
+          TimeLog[count]=nowTime;
+          count++;    
+          
+      }else{
+         
+         TimeLog[19]=nowTime;
+         
+         pc.printf("Hello World!\n");   
  
-int main() {
-    printf("Hello World!\n");   
- 
-    mkdir("/sd/mydir", 0777);
+         mkdir("/sd/mydir", 0777);
     
-    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
-    if(fp == NULL) {
+         FILE *fp = fopen("/sd/mydir/sdtest_kai.csv", "a");
+          if(fp == NULL) {
         error("Could not open file for write\n");
-    }
-    fprintf(fp, "Hello fun SD Card World!");
-    fclose(fp); 
+             }
+                  fprintf(fp, "%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n%d\r\n",TimeLog[0],TimeLog[1],TimeLog[2],TimeLog[3],TimeLog[4],TimeLog[5],TimeLog[6],TimeLog[7],TimeLog[8],TimeLog[9],TimeLog[10],TimeLog[11],TimeLog[12],TimeLog[13],TimeLog[14],TimeLog[15],TimeLog[16],TimeLog[17],TimeLog[18],TimeLog[19]);
+              myled1 = 1 ;
+              fclose(fp); 
+              free(fp);
+              
+              pc.printf("Goodbye World!\n");
+    
+               count=0;//カウントをリセットする
+               
+               }//if end
+     
+          __enable_irq();
+        }
  
-    printf("Goodbye World!\n");
-}
+ 
+ int main(){   
+        Time.start();
+        sd_write.attach(&SD,0.05);//0.05秒ごとにSDという関数を発動し、割り込みする。
+        
+    while(1){
+        nowTime = Time.read_ms();
+        }   
+}