Andrea Pallotta
/
Nucleo_analog_loop
import test
Revision 2:b4f8b72a22ec, committed 2018-02-25
- Comitter:
- andrewPV
- Date:
- Sun Feb 25 14:34:52 2018 +0000
- Parent:
- 1:89aa667d1a9b
- Commit message:
- Importing test
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Dec 19 14:55:38 2016 +0000 +++ b/main.cpp Sun Feb 25 14:34:52 2018 +0000 @@ -1,6 +1,6 @@ #include "mbed.h" -LocalFileSystem local("local"); // Create the local filesystem under the name "local" + AnalogIn in(A0); #if !DEVICE_ANALOGOUT @@ -9,18 +9,28 @@ AnalogOut out(PA_4); #endif +/* #if !DEVICE_FILEHANDLE +#error You cannot use this example as the FileHandle is not supported on this device. +#else +LocalFileSystem local("local"); // Create the local filesystem under the name "local" +#endif */ + DigitalOut led(LED1); +DigitalOut set(PB_0); int main() { - FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing +/* FILE *fp = fopen("/DETAILS.TXT", "w"); // Open "out.txt" on the local file system for writing fprintf(fp, "Hello World!"); - fclose(fp); + fclose(fp); */ printf("\nAnalog loop example\n"); printf("*** Connect A0 and PA_4 pins together ***\n"); - while(1) { + int i (0); + while(i <= 10) { + set.write(0); + float in_value = in.read(); for (float out_value = 0.0f; out_value < 1.1f; out_value += 0.1f) { // Output value using DAC out.write(out_value); @@ -28,8 +38,13 @@ // Read ADC input float in_value = in.read(); // Display difference between two values - float diff = fabs(out_value - in_value); - printf("(out:%.4f) - (in:%.4f) = (%.4f) ", out_value, in_value, diff); + float diff = fabs(out_value - in_value)*3.3f; + in_value *= 3.3f; + out_value *= 3.3f; + printf("(out:%.4f V) - (in:%.4f V) = (%.4f V) ", out_value, in_value, diff); + out_value /= 3.3f; + in_value /= 3.3f; + diff /= 3.3f; if (diff > 0.05f) { printf("FAIL\n"); } else { @@ -37,7 +52,11 @@ printf("\033[1A"); // Moves cursor up of 1 line } led = !led; + ++i; } + /* in_value *= 3.3f; + printf("(out:%.4f V)", in_value); + ++i; */ } }
--- a/mbed.bld Mon Dec 19 14:55:38 2016 +0000 +++ b/mbed.bld Sun Feb 25 14:34:52 2018 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/faff56e089b2 \ No newline at end of file