Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
I am trying to save the analog input into text file. Any idea why it only has one line written in the text file.
Here is the codes: /media/uploads/bjsrlu/main.txt
A Cut and paste version:
#include "mbed.h" // read the analog input, time stamp it into seconds and then write to file. AnalogIn input(p20); Serial pc(USBTX, USBRX); // tx, rx LocalFileSystem local("local"); // create the local file system under the name "local" DigitalIn enable(p10); int main() { FILE *fp = fopen ("/local/out.txt", "w"); // open out.txt" on the local file system for writing wait (5.0); unsigned short samples[1024]; set_time (1303037151); int exit = 0; while (exit == 0) { time_t seconds = time (NULL); pc.printf ("Time as seconds since January 1, 1970 = %d , 0x%04X\n", seconds, input.read_u16() ); fprintf (fp, "%d , 0x%04X\n", seconds, input.read_u16() ); if (enable) { // pull up VCC to stop the Analog Input Logging. exit = 1; wait (5); pc.printf ("About to close file in 5 seconds...."); fclose (fp); wait (5); pc.printf ("Halted..."); } wait_ms(200); fclose (fp); } // end of while (1) }