Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
Revision 2:b86f4a4aa079, committed 2018-10-16
- Comitter:
- kzar
- Date:
- Tue Oct 16 19:02:50 2018 +0000
- Parent:
- 1:e4d7342be507
- Commit message:
- SD Hello world using usb virtual com port
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r e4d7342be507 -r b86f4a4aa079 main.cpp --- a/main.cpp Tue May 16 05:18:55 2017 +0000 +++ b/main.cpp Tue Oct 16 19:02:50 2018 +0000 @@ -1,19 +1,31 @@ #include "mbed.h" #include "SDFileSystem.h" - + +Serial pc(USBTX, USBRX); SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board int main() { - printf("Hello World!\n"); - + //Write to the file and close it mkdir("/sd/mydir", 0777); - FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); if(fp == NULL) { error("Could not open file for write\n"); + pc.printf("fucccccckk"); } - fprintf(fp, "Hello fun SD Card World!"); - fclose(fp); + fprintf(fp, "Hello SD World!"); + fclose(fp); + + //Open the file and read out the data to the pc + fp = fopen("/sd/mydir/sdtest.txt", "r"); + char Buffer[256]; - printf("Goodbye World!\n"); + if(fp == NULL) { error("Could not open file for reading\r\n"); } + + while(fgets (Buffer, 256, fp) != NULL){ + Buffer[strlen(Buffer)-1] = 0; + pc.printf("\"%s\" \r\n", Buffer); + + } + + fclose(fp); }