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
main.cpp
00001 #include "mbed.h" 00002 #include "SDFileSystem.h" 00003 00004 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board 00005 DigitalIn enable(p30); 00006 AnalogIn inpt(p20); 00007 DigitalOut myled(LED1); 00008 00009 //float Log[16]={}; 00010 00011 Timer SDspeed; 00012 00013 void SD(int num, float btry, float time, float stack_time){ 00014 myled = 1; 00015 00016 // printf("Hello World!\n"); 00017 00018 mkdir("/sd/mydir", 0777); 00019 00020 00021 SDspeed.start(); 00022 00023 FILE *fp_csv = fopen("/sd/mydir/SDtestSpeed.csv", "a"); 00024 if(fp_csv == NULL) { 00025 error("Could not open file for write\n"); 00026 } 00027 00028 fprintf(fp_csv, "%d,%f,%.5f, %.5f\n", num, btry, time, stack_time); 00029 00030 fclose(fp_csv); 00031 00032 SDspeed.stop(); 00033 00034 00035 ///////////////// 00036 00037 // FILE *fp_txt = fopen("/sd/mydir/sdtest.txt", "a"); 00038 // if(fp_txt == NULL) { 00039 // error("Could not open file for write\n"); 00040 // } 00041 // fprintf(fp_txt, "Hello fun SD Card World!\n"); 00042 // fprintf(fp_txt, "Hello fun SD Card World!\n"); 00043 // fprintf(fp_txt, "%f,%f\n", btry, (float)num); 00044 // 00045 // fclose(fp_txt); 00046 00047 00048 printf("Goodbye World!\n"); 00049 myled = 0; 00050 } 00051 00052 int main() { 00053 float btry_lg = 0; 00054 int nmbr_lg = 0; 00055 float wrt_SD_time = 0; 00056 float sec = 0; 00057 00058 FILE *fp_csv = fopen("/sd/mydir/SDtestSpeed.csv", "w"); 00059 if(fp_csv == NULL) { 00060 error("Could not open file for write\n"); 00061 } 00062 fprintf(fp_csv, "number, battery, time\n"); 00063 fclose(fp_csv); 00064 00065 while(1){ 00066 // test the voltage on the initialized analog pin 00067 // and if greater than 0.3 * VCC set the digital pin 00068 // to a logic 1 otherwise a logic 0 00069 btry_lg = inpt.read()*3.3; 00070 00071 //if(ain > 0.3f) { 00072 //} else { 00073 //} 00074 00075 // print the percentage and 16 bit normalized values 00076 //printf("percentage: %3.3f%%\n", ain.read()*100.0f); 00077 //printf("normalized: 0x%04X \n", ain.read_u16()); 00078 //wait(0.2f); 00079 00080 nmbr_lg++; 00081 00082 SD(nmbr_lg, btry_lg, wrt_SD_time, sec); 00083 wrt_SD_time = SDspeed.read(); 00084 sec += wrt_SD_time; 00085 00086 wait_us(10); 00087 } 00088 }
Generated on Wed Aug 3 2022 04:18:29 by
1.7.2