private

Dependencies:   ADXL345 FATFileSystem LPS331_SPI mbed

Files at this revision

API Documentation at this revision

Comitter:
obaratakahiro
Date:
Sat Sep 16 05:24:37 2017 +0000
Parent:
1:9dc9b228c5b7
Commit message:
private

Changed in this revision

LPS25H.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9dc9b228c5b7 -r 6c4273f2f7ed LPS25H.lib
--- a/LPS25H.lib	Thu Sep 22 05:58:23 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/yasuyuki/code/LPS25H/#0d2babe81a04
diff -r 9dc9b228c5b7 -r 6c4273f2f7ed main.cpp
--- a/main.cpp	Thu Sep 22 05:58:23 2016 +0000
+++ b/main.cpp	Sat Sep 16 05:24:37 2017 +0000
@@ -1,45 +1,76 @@
-#include "mbed.h"
+#include "mbed.h"              
 #include "SDFileSystem.h"
 #include "LPS331_SPI.h"
 #include "ADXL345.h"
-DigitalOut myled(LED1);
-LPS331_SPI press(dp2, dp1, dp6, dp26);
-SDFileSystem sd(dp2, dp1, dp6, dp17, "sd");
-AnalogIn sensor (dp4);
-ADXL345 accelerometer(dp2, dp1, dp6, dp25);
-Serial pc(USBTX, USBRX); 
+/*do include*/
+DigitalOut myled(LED1);/*dp28 no LED*/
+LPS331_SPI press(dp2, dp1, dp6, dp26);/*pressure no sengen*/
+SDFileSystem sd(dp2, dp1, dp6, dp17, "sd"); /**/
+AnalogIn sensor(dp4);
+ADXL345 accelerometer(dp2,dp1,dp6,dp25);
+Serial pc(USBTX,USBRX);
+/*sengensuru*/
 
 int main()
 {
-   int readings[3] = {0, 0, 0};
-    
+    int readings[3] = {0,0,0};
     accelerometer.setPowerControl(0x00);
     accelerometer.setDataFormatControl(0x0B);
     accelerometer.setDataRate(ADXL345_3200HZ);
     accelerometer.setPowerControl(0x08);
+    
+    
     press.quickStart();
     
-    int count;
+    int cl;
+    int pr;
+    
+    FILE *fp = fopen("/sd/sdtest.txt","a");
+        if (fp == NULL) {
+            printf("fopen error\n");
+            
+            }
+    pr = fprintf(fp, "START");
+        if (pr < 0){
+            printf("fprintf error\n");
+            }
+            
+    cl = fclose(fp);
+    if(cl == EOF){
+            printf("fclose error\n");
+            }
+            
     
     while(1){
-       FILE *fp = fopen("/sd/sdtest.txt", "a");
-        if(fp == NULL) {
-            error("Could not open file for write\n");
-        }
         float ain = sensor;
         float pressure;
         accelerometer.getOutput(readings);
         pressure = press.getPressure();
         ain = (ain * 3.3 - 0.6) / 0.01;
         
-        count = fprintf(fp,"%f\r\n%f\r\n%i\r\n%i\r\n%i\r\n",pressure,ain,(int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
-        if ( count < 0 ) {
-            printf("ファイルの書込みに失敗しました.\n");
+        FILE *fp = fopen("/sd/sdtest.txt","a");
+        if (fp == NULL) {
+            printf("fopen error\n");
+            
+            }
+            
+        pr = fprintf(fp, "%f\r\n%f\r\n%i\r\n%i\r\n%i\r\n",pressure,ain,(int16_t)readings[0],(int16_t)readings[1],(int16_t)readings[2]);
+        if (pr < 0){
+            printf("fprintf error\n");
+            
+            }
+        
+        printf("%f\r\n%f\r\n%i\r\n%i\r\n%i\r\n",pressure,ain,(int16_t)readings[0],(int16_t)readings[1],(int16_t)readings[2]);
+        
+        cl = fclose(fp);
+        if(cl == EOF){
+            printf("fclose error\n");
+            
+            }
+        
+        free(fp);
+        
+        myled = !myled;
+        wait(0.1);
         }
-
-
-        fclose(fp);
-        myled = !myled;
-        wait(0.5);
-    }
 }