1

Dependencies:   SDFileSystem mbed

Committer:
tangcan0823
Date:
Fri Oct 21 04:16:12 2016 +0000
Revision:
0:2ff730fe4ebd
sample;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tangcan0823 0:2ff730fe4ebd 1 // example writing to SD card, sford
tangcan0823 0:2ff730fe4ebd 2
tangcan0823 0:2ff730fe4ebd 3 #include "mbed.h"
tangcan0823 0:2ff730fe4ebd 4 #include "SDFileSystem.h"
tangcan0823 0:2ff730fe4ebd 5
tangcan0823 0:2ff730fe4ebd 6 SDFileSystem sd(p25, p28, p29, p21, "sd"); // the pinout on the mbed Cool Components workshop board
tangcan0823 0:2ff730fe4ebd 7
tangcan0823 0:2ff730fe4ebd 8 int main() {
tangcan0823 0:2ff730fe4ebd 9 printf("Hello World!\n");
tangcan0823 0:2ff730fe4ebd 10
tangcan0823 0:2ff730fe4ebd 11 mkdir("/sd/mydir", 0777);
tangcan0823 0:2ff730fe4ebd 12
tangcan0823 0:2ff730fe4ebd 13 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
tangcan0823 0:2ff730fe4ebd 14 if(fp == NULL) {
tangcan0823 0:2ff730fe4ebd 15 error("Could not open file for write\n");
tangcan0823 0:2ff730fe4ebd 16 }
tangcan0823 0:2ff730fe4ebd 17 fprintf(fp, "Hello fun SD Card World!");
tangcan0823 0:2ff730fe4ebd 18 fclose(fp);
tangcan0823 0:2ff730fe4ebd 19
tangcan0823 0:2ff730fe4ebd 20 printf("Goodbye World!\n");
tangcan0823 0:2ff730fe4ebd 21 }