SDcard
Dependencies: mbed PowerControl SDFileSystem
Fork of SDFilesystem by
main.cpp@1:47daa1a922c4, 2016-12-13 (annotated)
- Committer:
- tomoya123
- Date:
- Tue Dec 13 07:06:47 2016 +0000
- Revision:
- 1:47daa1a922c4
- Parent:
- 0:8d235efb1150
SDFilesystem
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomoya123 | 0:8d235efb1150 | 1 | #include "mbed.h" |
tomoya123 | 0:8d235efb1150 | 2 | #include "SDFileSystem.h" |
tomoya123 | 1:47daa1a922c4 | 3 | |
tomoya123 | 0:8d235efb1150 | 4 | Serial pc(USBTX,USBRX); |
tomoya123 | 0:8d235efb1150 | 5 | SDFileSystem sd(p11, p12, p13, p15, "sd"); |
tomoya123 | 0:8d235efb1150 | 6 | |
tomoya123 | 0:8d235efb1150 | 7 | int main() { |
tomoya123 | 1:47daa1a922c4 | 8 | pc.baud(9600); |
tomoya123 | 0:8d235efb1150 | 9 | pc.printf("Hello world!\r\n"); |
tomoya123 | 1:47daa1a922c4 | 10 | char str[100]; |
tomoya123 | 1:47daa1a922c4 | 11 | mkdir("/sd/mydir", 0777); |
tomoya123 | 0:8d235efb1150 | 12 | printf("helloworld\r\n"); |
tomoya123 | 1:47daa1a922c4 | 13 | FILE *fp = fopen("/sd/mydir/sdtest.txt","w"); |
tomoya123 | 0:8d235efb1150 | 14 | if(fp == NULL) { |
tomoya123 | 0:8d235efb1150 | 15 | error("Could not open file for write\r\n"); |
tomoya123 | 0:8d235efb1150 | 16 | } |
tomoya123 | 0:8d235efb1150 | 17 | for(int i=0;i<10;i++)fprintf(fp,"Hello my name is HEPTA!\r\n"); |
tomoya123 | 0:8d235efb1150 | 18 | fclose(fp); |
tomoya123 | 0:8d235efb1150 | 19 | fp = fopen("/sd/mydir/sdtest.txt","r"); |
tomoya123 | 1:47daa1a922c4 | 20 | fgets(str,100,fp); |
tomoya123 | 1:47daa1a922c4 | 21 | puts(str); |
tomoya123 | 0:8d235efb1150 | 22 | fclose(fp); |
tomoya123 | 0:8d235efb1150 | 23 | printf("Goodbye!!\r\n"); |
tomoya123 | 0:8d235efb1150 | 24 | } |