
SD leseing til array
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
main.cpp@1:d84eab100439, 2017-04-18 (annotated)
- Committer:
- mathimat
- Date:
- Tue Apr 18 08:13:59 2017 +0000
- Revision:
- 1:d84eab100439
- Parent:
- 0:bdbd3d6fc5d5
- Child:
- 2:57156358b223
THE SD works!!!
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" |
mathimat | 1:d84eab100439 | 3 | |
mathimat | 1:d84eab100439 | 4 | SDFileSystem sd(p5, p6, p7, p20, "sd"); // the pinout on the mbed Cool Components workshop board |
mathimat | 1:d84eab100439 | 5 | |
mathimat | 1:d84eab100439 | 6 | char filer[64][64]; |
mathimat | 1:d84eab100439 | 7 | |
mathimat | 1:d84eab100439 | 8 | |
mathimat | 1:d84eab100439 | 9 | |
mathimat | 1:d84eab100439 | 10 | int main() |
mathimat | 1:d84eab100439 | 11 | { |
mathimat | 1:d84eab100439 | 12 | |
mathimat | 1:d84eab100439 | 13 | |
mathimat | 1:d84eab100439 | 14 | DIR *d; |
mathimat | 1:d84eab100439 | 15 | struct dirent *dir; |
mathimat | 1:d84eab100439 | 16 | d = opendir("/sd"); |
mathimat | 1:d84eab100439 | 17 | char buffer[64]; |
mathimat | 1:d84eab100439 | 18 | if (d) { |
mathimat | 1:d84eab100439 | 19 | int i = 0; |
mathimat | 1:d84eab100439 | 20 | while ((dir = readdir(d)) != NULL) { |
mathimat | 1:d84eab100439 | 21 | sprintf(buffer, "%s", dir->d_name); |
mathimat | 1:d84eab100439 | 22 | if (!strcmp(strrchr(buffer, '\0') - 4, ".wav")) { |
mathimat | 1:d84eab100439 | 23 | if (strncmp(buffer, ".",1)) { |
mathimat | 1:d84eab100439 | 24 | printf(":: %s ::\r\n",buffer); |
mathimat | 1:d84eab100439 | 25 | strcpy(filer[i], buffer); |
mathimat | 1:d84eab100439 | 26 | i++; |
mathimat | 1:d84eab100439 | 27 | } |
mathimat | 1:d84eab100439 | 28 | } |
mathimat | 1:d84eab100439 | 29 | } |
mathimat | 1:d84eab100439 | 30 | |
mathimat | 1:d84eab100439 | 31 | closedir(d); |
mbed_official | 0:bdbd3d6fc5d5 | 32 | } |
mathimat | 1:d84eab100439 | 33 | |
mathimat | 1:d84eab100439 | 34 | printf("fin\r\n"); |
mathimat | 1:d84eab100439 | 35 | for(int i = 0; i<6; i++) { |
mathimat | 1:d84eab100439 | 36 | printf("%s - \r\n",filer[i]); |
mathimat | 1:d84eab100439 | 37 | } |
mathimat | 1:d84eab100439 | 38 | return(0); |
mathimat | 1:d84eab100439 | 39 | |
mathimat | 1:d84eab100439 | 40 | |
mbed_official | 0:bdbd3d6fc5d5 | 41 | } |