Hi,
I'm not well versed in C, I got some help sticking a few programs together to serve a basic purpose, and I've been modifying it to further suit my needs.
Here is the code:
#include "mbed.h"
#define ON 1
#define OFF 0
LocalFileSystem local("local");
AnalogIn myinput(p20);
DigitalOut myled(p5);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
float analog_value;
int count = 0;
int main() {
printf("Read and store 100 analog sample at 0.5 sec interval\r\n");
FILE *fp = fopen("/local/analog.txt","w"); // Open a file to save samples
printf("File analog.txt is open.\r\n");
analog_value = myinput.read(); // Read analog (range 0.0 to 1.0)
if (analog_value > 0.6) // If value is above 0.3, then store
{
while (count < 100) {
fprintf (fp, "%3i: %f \r\n", count+1, analog_value);
led1 = ON; // Turn LED ON if sample was stored.
printf ("%3i: %f\r\n", count+1, analog_value);
count++; // Increment sample counter.
led2 = ON; // LED2 ON.
wait_ms(50); // Wait 0.05 second
led2 = OFF; // LED2 OFF.
wait_ms(50); // Wait 0.05 second
fclose(fp); // Close the sampe file after 100 samples read.
printf("File analog.txt closed.\r\n");
printf("Finished. 100 samples taken. Bye!\r\n");
}
else {
fprintf (fp, "%3i: %f [below]\r\n", count+1, analog_value);
led2 = ON;
wait_ms(50);
led2 = Off;
}
}
}
Not my work for the most part (thanks D. Wendelboe)
Basically I want this to now evaluate a measured voltage and record the values over the next short length of time, IF the values is over a limit, other wise to continue to poll the value.
However, when compiling I get an error "E127" on line 50 (the line with else) along with "expected a statement".
Ultimately I'd like the output file to have be named the time at which the initial value crossed the threshold, any hint with that would be great (the RTC on mbed seems kind of difficult to maneuver).
Hi,
I'm not well versed in C, I got some help sticking a few programs together to serve a basic purpose, and I've been modifying it to further suit my needs.
Here is the code:
Basically I want this to now evaluate a measured voltage and record the values over the next short length of time, IF the values is over a limit, other wise to continue to poll the value.
However, when compiling I get an error "E127" on line 50 (the line with else) along with "expected a statement".
Ultimately I'd like the output file to have be named the time at which the initial value crossed the threshold, any hint with that would be great (the RTC on mbed seems kind of difficult to maneuver).