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: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
Revision 1:3d3fb5f81373, committed 2017-05-30
- Comitter:
- aaaaaYukiaaaaa
- Date:
- Tue May 30 04:55:17 2017 +0000
- Parent:
- 0:bdbd3d6fc5d5
- Child:
- 2:ee19d6b4dc98
- Commit message:
- This program is writing data only.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Dec 07 11:25:01 2012 +0000
+++ b/main.cpp Tue May 30 04:55:17 2017 +0000
@@ -2,18 +2,83 @@
#include "SDFileSystem.h"
SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+DigitalIn enable(p30);
+AnalogIn inpt(p20);
+DigitalOut myled(LED1);
-int main() {
+
+void SD(int num, double btry){
+ myled = 1;
+
printf("Hello World!\n");
mkdir("/sd/mydir", 0777);
- FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
- if(fp == NULL) {
+ FILE *fp_csv = fopen("/sd/mydir/sdtest.csv", "a");
+ if(fp_csv == NULL) {
+ error("Could not open file for write\n");
+ }
+
+ fprintf(fp_csv, "%f,%f\n", btry, (float)num);
+
+ fclose(fp_csv);
+
+ /////////////////
+
+// FILE *fp_txt = fopen("/sd/mydir/sdtest.txt", "a");
+// if(fp_txt == NULL) {
+// error("Could not open file for write\n");
+// }
+// fprintf(fp_txt, "Hello fun SD Card World!\n");
+// fprintf(fp_txt, "Hello fun SD Card World!\n");
+// fprintf(fp_txt, "%f,%f\n", btry, (float)num);
+//
+// fclose(fp_txt);
+
+
+ printf("Goodbye World!\n");
+ myled = 0;
+}
+
+int main() {
+ float btry_lg = 0;
+ int nmbr_lg = 0;
+
+ FILE *fp_csv = fopen("/sd/mydir/sdtest.csv", "w");
+ if(fp_csv == NULL) {
error("Could not open file for write\n");
}
- fprintf(fp, "Hello fun SD Card World!");
- fclose(fp);
-
- printf("Goodbye World!\n");
+ fprintf(fp_csv, "baterry,number\n");
+ fclose(fp_csv);
+
+
+// FILE *fp_txt = fopen("/sd/mydir/sdtest.txt", "a");
+// if(fp_txt == NULL) {
+// error("Could not open file for write\n");
+// }
+// fclose(fp_txt);
+
+
+ while(1){
+ // test the voltage on the initialized analog pin
+ // and if greater than 0.3 * VCC set the digital pin
+ // to a logic 1 otherwise a logic 0
+ btry_lg = inpt.read()*3.3;
+
+ //if(ain > 0.3f) {
+
+ //} else {
+
+ //}
+
+ // print the percentage and 16 bit normalized values
+ //printf("percentage: %3.3f%%\n", ain.read()*100.0f);
+ //printf("normalized: 0x%04X \n", ain.read_u16());
+ //wait(0.2f);
+
+ nmbr_lg++;
+ SD(nmbr_lg, btry_lg);
+
+ wait(0.1);
+ }
}
