Make sure the speed of writing to microSD.
Dependencies: SDFileSystem mbed
main.cpp
- Committer:
- aaaaaYukiaaaaa
- Date:
- 2017-05-30
- Revision:
- 0:b179d330bb2e
File content as of revision 0:b179d330bb2e:
#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);
//float Log[16]={};
Timer SDspeed;
void SD(int num, float btry, float time, float stack_time){
myled = 1;
// printf("Hello World!\n");
mkdir("/sd/mydir", 0777);
SDspeed.start();
FILE *fp_csv = fopen("/sd/mydir/SDtestSpeed.csv", "a");
if(fp_csv == NULL) {
error("Could not open file for write\n");
}
fprintf(fp_csv, "%d,%f,%.5f, %.5f\n", num, btry, time, stack_time);
fclose(fp_csv);
SDspeed.stop();
/////////////////
// 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;
float wrt_SD_time = 0;
float sec = 0;
FILE *fp_csv = fopen("/sd/mydir/SDtestSpeed.csv", "w");
if(fp_csv == NULL) {
error("Could not open file for write\n");
}
fprintf(fp_csv, "number, battery, time\n");
fclose(fp_csv);
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, wrt_SD_time, sec);
wrt_SD_time = SDspeed.read();
sec += wrt_SD_time;
wait_us(10);
}
}