Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG SDFileSystem mbed
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
+ }
+}