Dependencies:   SDFileSystem mbed

Fork of Seeed_SDCard_Shield by Shields

Files at this revision

API Documentation at this revision

Comitter:
jvicente
Date:
Wed Dec 14 16:22:59 2016 +0000
Parent:
4:0928d6e00f01
Commit message:
Version 1. Funciona

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 0928d6e00f01 -r 197a2b770c24 main.cpp
--- a/main.cpp	Fri Feb 13 09:40:18 2015 +0000
+++ b/main.cpp	Wed Dec 14 16:22:59 2016 +0000
@@ -1,45 +1,57 @@
-/* Copyright (c) 2010-2011 mbed.org, MIT License
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-* and associated documentation files (the "Software"), to deal in the Software without
-* restriction, including without limitation the rights to use, copy, modify, merge, publish,
-* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in all copies or
-* substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
-* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
 #include "mbed.h"
 #include "SDFileSystem.h"
+SDFileSystem sd(D11, D12, D13, D10, "sd");
 
-Serial pc(USBTX, USBRX);
-SDFileSystem sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCK, CS
-FILE *fp;
+
+int main()
+{
+    float valorA;
+    float valorB;
+
+    wait(2.0);
+    printf("Comienza Programa!\n\r");
+
 
-int main() {
-    wait(2);
-    pc.printf("Initializing\r\n");
-    
-    fp = fopen("/sd/hello.txt", "r");
-    if (fp != NULL) {
+    //Fichero para almacenar datos
+    FILE *fpActual = fopen("/sd/sdtest.bin", "r");
+    if(fpActual == NULL) {
+        printf("No Existe el fichero\n\r");
+        valorA=0.0;
+        valorB=100.0;
+    } else {
+        fread(&valorA,4,1,fpActual);
+        fread(&valorB,4,1,fpActual);
+        fclose(fpActual);
+    }
+
+    printf("El dato a es: %f y el dato b es: %f\n\r",valorA,valorB);
+
+    for (int i=0; i<10; i++) {
+        wait(0.5);
+
+        ////Fichero valor Actual
+        FILE *fp = fopen("/sd/sdtest.bin", "w");
+        if(fp == NULL) {
+            printf("El fichero no se puede abrir para escribir\n\r");
+        } else {
+            printf("El dato a es: %f y el dato b es: %f\n\r",valorA,valorB);
+            fwrite(&valorA,4,1,fp);
+            fwrite(&valorB,4,1,fp);
+        }
         fclose(fp);
-        remove("/sd/hello.txt");
-        pc.printf("Remove an existing file with the same name\r\n");
+
+        ////Fichero valor Actual
+        FILE *fpCSV = fopen("/sd/sdtest.csv", "a");
+        if(fpCSV == NULL) {
+            printf("El fichero no se puede abrir para escribir\n\r");
+        } else {
+            fprintf(fpCSV,"%f;%f\n",valorA,valorB);
+        }
+        fclose(fpCSV);
+        valorA++;
+        valorB++;
+
     }
-    
-    fp = fopen("/sd/hello.txt", "w");
-    if (fp == NULL) {
-        pc.printf("Unable to write the file\r\n");
-    } else {
-        fprintf(fp, "mbed SDCard application!");
-        fclose(fp);
-        pc.printf("File successfully written!\r\n");
-    }
+    printf("FIN!\n");
 }
+