Pedro Cruz
/
Nucleo_read_analog_value
ad test
main.cpp@3:c8e6635e6f4b, 2016-10-28 (annotated)
- Committer:
- pedro_C
- Date:
- Fri Oct 28 13:37:10 2016 +0000
- Revision:
- 3:c8e6635e6f4b
- Parent:
- 1:0490a15c76e4
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:c2d1ad5059da | 1 | #include "mbed.h" |
bcostm | 1:0490a15c76e4 | 2 | |
pedro_C | 3:c8e6635e6f4b | 3 | AnalogIn analog_1(PA_3); |
pedro_C | 3:c8e6635e6f4b | 4 | AnalogIn analog_2(PC_0); |
pedro_C | 3:c8e6635e6f4b | 5 | AnalogIn analog_3(PC_3); |
pedro_C | 3:c8e6635e6f4b | 6 | AnalogIn analog_4(PF_3); |
pedro_C | 3:c8e6635e6f4b | 7 | AnalogIn analog_5(PF_10); |
pedro_C | 3:c8e6635e6f4b | 8 | AnalogIn analog_6(PA_7); |
pedro_C | 3:c8e6635e6f4b | 9 | AnalogIn analog_7(PF_8); |
pedro_C | 3:c8e6635e6f4b | 10 | AnalogIn analog_8(PF_7); |
pedro_C | 3:c8e6635e6f4b | 11 | AnalogIn analog_9(PF_9); |
pedro_C | 3:c8e6635e6f4b | 12 | |
pedro_C | 3:c8e6635e6f4b | 13 | Serial pc(USBTX,USBRX); |
pedro_C | 3:c8e6635e6f4b | 14 | |
pedro_C | 3:c8e6635e6f4b | 15 | Timer t; |
pedro_C | 3:c8e6635e6f4b | 16 | |
pedro_C | 3:c8e6635e6f4b | 17 | |
pedro_C | 3:c8e6635e6f4b | 18 | int main() |
pedro_C | 3:c8e6635e6f4b | 19 | { |
pedro_C | 3:c8e6635e6f4b | 20 | t.start(); |
pedro_C | 3:c8e6635e6f4b | 21 | pc.baud(115200); |
bcostm | 1:0490a15c76e4 | 22 | float meas; |
pedro_C | 3:c8e6635e6f4b | 23 | |
pedro_C | 3:c8e6635e6f4b | 24 | // pc.printf("\nAnalogIn example\n"); |
pedro_C | 3:c8e6635e6f4b | 25 | |
bcostm | 1:0490a15c76e4 | 26 | while(1) { |
pedro_C | 3:c8e6635e6f4b | 27 | pc.printf("%f seconds\t", t.read()); |
pedro_C | 3:c8e6635e6f4b | 28 | meas = analog_1.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
pedro_C | 3:c8e6635e6f4b | 29 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
pedro_C | 3:c8e6635e6f4b | 30 | pc.printf("%.0f mV, \t", meas); |
pedro_C | 3:c8e6635e6f4b | 31 | |
pedro_C | 3:c8e6635e6f4b | 32 | meas = analog_2.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
pedro_C | 3:c8e6635e6f4b | 33 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
pedro_C | 3:c8e6635e6f4b | 34 | pc.printf("%.0f mV, \t", meas); |
pedro_C | 3:c8e6635e6f4b | 35 | |
pedro_C | 3:c8e6635e6f4b | 36 | meas = analog_3.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
pedro_C | 3:c8e6635e6f4b | 37 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
pedro_C | 3:c8e6635e6f4b | 38 | pc.printf("%.0f mV, \t", meas); |
pedro_C | 3:c8e6635e6f4b | 39 | |
pedro_C | 3:c8e6635e6f4b | 40 | meas = analog_4.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
bcostm | 1:0490a15c76e4 | 41 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
pedro_C | 3:c8e6635e6f4b | 42 | pc.printf("%.0f mV, \t", meas); |
pedro_C | 3:c8e6635e6f4b | 43 | |
pedro_C | 3:c8e6635e6f4b | 44 | meas = analog_5.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
pedro_C | 3:c8e6635e6f4b | 45 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
pedro_C | 3:c8e6635e6f4b | 46 | pc.printf("%.0f mV, \t", meas); |
pedro_C | 3:c8e6635e6f4b | 47 | |
pedro_C | 3:c8e6635e6f4b | 48 | meas = analog_6.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
pedro_C | 3:c8e6635e6f4b | 49 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
pedro_C | 3:c8e6635e6f4b | 50 | pc.printf("%.0f mV, \t\t", meas); |
pedro_C | 3:c8e6635e6f4b | 51 | |
pedro_C | 3:c8e6635e6f4b | 52 | meas = analog_7.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
pedro_C | 3:c8e6635e6f4b | 53 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
pedro_C | 3:c8e6635e6f4b | 54 | pc.printf("%.0f mV, \t", meas); |
pedro_C | 3:c8e6635e6f4b | 55 | |
pedro_C | 3:c8e6635e6f4b | 56 | meas = analog_8.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
pedro_C | 3:c8e6635e6f4b | 57 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
pedro_C | 3:c8e6635e6f4b | 58 | pc.printf("%.0f mV, \t", meas); |
pedro_C | 3:c8e6635e6f4b | 59 | |
pedro_C | 3:c8e6635e6f4b | 60 | meas = analog_9.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
pedro_C | 3:c8e6635e6f4b | 61 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
pedro_C | 3:c8e6635e6f4b | 62 | pc.printf("%.0f mV, \n", meas); |
pedro_C | 3:c8e6635e6f4b | 63 | |
pedro_C | 3:c8e6635e6f4b | 64 | wait_ms(20); |
bcostm | 0:c2d1ad5059da | 65 | } |
bcostm | 0:c2d1ad5059da | 66 | } |