Dear all,
I am building a data logger now. I can save all data (analog inputs) to a filename called "temp1.txt" in local file system upon triggering a button.
Say, I need to keep the file and acquire new set of data. How to keep the files in RAM and do not overwrite the same file? I have copied some codes from Igor Skochinsky:
#include "mbed.h"
AnalogIn xin(p20);
AnalogIn yin(p19);
LocalFileSystem local("local"); // Create the local filesystem under the name "local"
int file_no;
char filename[256];
write_file() {
float xval;
float yval;
int loop=0;
sprintf(filename, "/local/temp%d.txt", file_no); // Open "tem%d.txt" on the local file system for writing
FILE *fout = fopen(filename, "w");
if ( fout != NULL ) {
while(1){
loop=loop+1;
xval=xin.read();
yval=yin.read();
fprintf(fout, "x: %f, y: %f\r\n", xval, yval);
if (loop>=10000) break;
}
fclose(fout);
file_no++;
}
}
int main() {
file_no = 1; // start from 1
button.attach(write_file);
while(1);
}
However, there are two problems while I complied it.
1. Explicity type is missing for the function of write_file. Should that be 'int write_file()'? What is the type of value returned from that function?
2. For 'button.attach(write_file)', identifier button is undefined. How can I defined the button?
Cheers.
Dear all,
I am building a data logger now. I can save all data (analog inputs) to a filename called "temp1.txt" in local file system upon triggering a button.
Say, I need to keep the file and acquire new set of data. How to keep the files in RAM and do not overwrite the same file? I have copied some codes from Igor Skochinsky:
1. Explicity type is missing for the function of write_file. Should that be 'int write_file()'? What is the type of value returned from that function?
2. For 'button.attach(write_file)', identifier button is undefined. How can I defined the button?
Cheers.