Hepta SD
Dependencies: SDFileSystem mbed
Fork of Lab7-01_template by
main.cpp@13:4fb761757895, 2017-09-07 (annotated)
- Committer:
- HEPTA
- Date:
- Thu Sep 07 23:43:35 2017 +0000
- Revision:
- 13:4fb761757895
- Parent:
- 10:4d6870d0caa0
- Child:
- 14:1c1a7c1f1228
Hepta Lab3
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" |
umeume | 2:1c5cdb2c3e0f | 3 | |
umeume | 2:1c5cdb2c3e0f | 4 | Serial pc(USBTX,USBRX); |
HEPTA | 9:942eb6e8c117 | 5 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
umeume | 2:1c5cdb2c3e0f | 6 | |
HEPTA | 13:4fb761757895 | 7 | int main(){ |
HEPTA | 13:4fb761757895 | 8 | pc.baud(9600); |
HEPTA | 13:4fb761757895 | 9 | pc.printf("Hello world!\r\n"); |
HEPTA | 13:4fb761757895 | 10 | char str[100]; |
HEPTA | 13:4fb761757895 | 11 | mkdir("/sd/mydir", 0777); |
HEPTA | 13:4fb761757895 | 12 | FILE *fp = fopen("/sd/mydir/test.txt","w"); |
HEPTA | 13:4fb761757895 | 13 | if(fp == NULL) { |
HEPTA | 13:4fb761757895 | 14 | error("Could not open file for write\r\n"); |
HEPTA | 13:4fb761757895 | 15 | } |
HEPTA | 13:4fb761757895 | 16 | for(int i=0; i<10; i++)fprintf(fp,"Hello my name is HEPTA!\r\n"); |
HEPTA | 13:4fb761757895 | 17 | fclose(fp); |
HEPTA | 13:4fb761757895 | 18 | fp = fopen("/sd/mydir/test.txt","r"); |
HEPTA | 13:4fb761757895 | 19 | fgets(str,100,fp); |
HEPTA | 13:4fb761757895 | 20 | puts(str); |
HEPTA | 13:4fb761757895 | 21 | fclose(fp); |
HEPTA | 13:4fb761757895 | 22 | pc.printf("Goodbye!!\r\n"); |
umeume | 2:1c5cdb2c3e0f | 23 | } |