This demo reads a bitmap from a FAT formatted SD-card, copies it to flash and displays it on the screen. The demo is based on the following project: https://os.mbed.com/users/DieterGraef/code/DISCO-F746NG_SDFileSystem/
Dependencies: LCD_DISCO_F746NG TS_DISCO_F746NG mbed FATFileSystem
Fork of DISCO-F746NG_SDFileSystem by
Diff: main.cpp
- Revision:
- 0:134f7a094930
- Child:
- 1:7f463f6f904e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 31 17:43:47 2016 +0000 @@ -0,0 +1,52 @@ +#include "mbed.h" +#include "SDFileSystem.h" +#include <stdio.h> + +DigitalOut myled(LED1); +SDFileSystem sd("sd"); + +// trim '\n' +void ntrim(char *str) +{ + int i; + for (i = 0; str[i] != 0; ++i); + + if (i > 0 && str[i - 1] == '\n') + str[i - 1] = 0; +} + + +int main() { + sd.mount(); + FILE * fp; + fp = fopen("/sd/test.txt", "w"); + if (fp == NULL) + { + printf("open error!!\r\n"); + while(1); + } + fprintf(fp,"Writing to SD Card"); + fclose (fp); + fp = fopen("/sd/test.txt", "r"); + if (fp == NULL) + { + printf("open error!!\r\n"); + while(1); + } + // read text file + char buf[1024]; + while (fgets(buf, sizeof(buf), fp) != NULL) + { + ntrim(buf); + printf("%s\r\n", buf); + } + + // file close + fclose(fp); + while(1) { + myled = 1; // LED is ON + wait(0.2); // 200 ms + myled = 0; // LED is OFF + wait(1.0); // 1 sec + } +}