The program will open a file called test.txt in the root of the SD card, and will create one if it does not exist. It will then write "one two three four five" in the .txt file. It will then read the text and output the result. You will need a terminal application (I recommend PuTTy) in order to see the outputs. The current program overwrites anything that was previous on the SD card. To prevent this, change the "w" to "a" during the writing process. This changes the instruction from a 'write' to an 'append'.
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
main.cpp@0:bdbd3d6fc5d5, 2012-12-07 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Dec 07 11:25:01 2012 +0000
- Revision:
- 0:bdbd3d6fc5d5
- Child:
- 1:2cf8f0893afd
First commit of SDFileSystem Hello World
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
mbed_official | 0:bdbd3d6fc5d5 | 3 | |
mbed_official | 0:bdbd3d6fc5d5 | 4 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board |
mbed_official | 0:bdbd3d6fc5d5 | 5 | |
mbed_official | 0:bdbd3d6fc5d5 | 6 | int main() { |
mbed_official | 0:bdbd3d6fc5d5 | 7 | printf("Hello World!\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 8 | |
mbed_official | 0:bdbd3d6fc5d5 | 9 | mkdir("/sd/mydir", 0777); |
mbed_official | 0:bdbd3d6fc5d5 | 10 | |
mbed_official | 0:bdbd3d6fc5d5 | 11 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
mbed_official | 0:bdbd3d6fc5d5 | 12 | if(fp == NULL) { |
mbed_official | 0:bdbd3d6fc5d5 | 13 | error("Could not open file for write\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 14 | } |
mbed_official | 0:bdbd3d6fc5d5 | 15 | fprintf(fp, "Hello fun SD Card World!"); |
mbed_official | 0:bdbd3d6fc5d5 | 16 | fclose(fp); |
mbed_official | 0:bdbd3d6fc5d5 | 17 | |
mbed_official | 0:bdbd3d6fc5d5 | 18 | printf("Goodbye World!\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 19 | } |