Writing to micro SD only.
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
main.cpp
- Committer:
- aaaaaYukiaaaaa
- Date:
- 2017-05-30
- Revision:
- 2:ee19d6b4dc98
- Parent:
- 1:3d3fb5f81373
File content as of revision 2:ee19d6b4dc98:
#include "mbed.h" #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); void SD(int num, double btry); 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_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); } } void SD(int num, double btry){ myled = 1; printf("Hello World!\n"); mkdir("/sd/mydir", 0777); 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; }