Writing to micro SD only.
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
Diff: main.cpp
- Revision:
- 1:3d3fb5f81373
- Parent:
- 0:bdbd3d6fc5d5
- Child:
- 2:ee19d6b4dc98
--- 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); + } }