SD card read data
Dependencies: SDFileSystem SDFileSystem_HelloWorld mbed
Fork of SDFileSystem_HelloWorld by
Diff: main.cpp
- Revision:
- 1:a305ecc5c0cb
- Parent:
- 0:bdbd3d6fc5d5
--- a/main.cpp Fri Dec 07 11:25:01 2012 +0000 +++ b/main.cpp Thu May 11 08:24:00 2017 +0000 @@ -1,19 +1,37 @@ #include "mbed.h" #include "SDFileSystem.h" -SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board +SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); //mosi, miso, sclk, cs +Serial pc(USBTX,USBRX); int main() { - printf("Hello World!\n"); - - 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); - - printf("Goodbye World!\n"); -} + char i=0; + float data; + char c,data1[8]; + + FILE *fp = fopen("/sd/dat12.dat", "r"); + while(1) + { + c = fgetc(fp); + data1[i] = c; + if((data1[i] == '\r')) + { + data = atof(data1); + i=0; + pc.printf("%0.3f\r\n",data); + wait(1); + } + else + { + i++; + } + + if(feof(fp)) + { + break ; + } + wait_ms(10); + } + fclose(fp); + return 0; +} \ No newline at end of file