Jose Rios
/
Nucleo_AnalogRead
Read an analog value using ADC
Revision 5:61fd7faf824b, committed 2014-12-29
- Comitter:
- jose_23991
- Date:
- Mon Dec 29 11:25:17 2014 +0000
- Parent:
- 4:643030f4ac01
- Commit message:
- Version 1.4
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 643030f4ac01 -r 61fd7faf824b main.cpp --- a/main.cpp Mon Dec 29 01:33:31 2014 +0000 +++ b/main.cpp Mon Dec 29 11:25:17 2014 +0000 @@ -1,7 +1,7 @@ -/***********************************************************************************************/ -/* Note: The STM32F401 has default 3.3V ADC pins */ -/* Note: The STM32F401 has default 12 bits ADC but it is normalized to 16 bits (2^16 -> 65536) */ -/***********************************************************************************************/ +/******************************************************************************************************/ +/* Note: The STM32F401 has default 3.3V ADC pins */ +/* Note: The STM32F401 has default 12 bits ADC but it is normalized to 16 bits (2^16 -> 65536 values) */ +/******************************************************************************************************/ #include "mbed.h" @@ -15,13 +15,13 @@ while(1) { - adc_value = analog_sensor.read_u16(); // Read the ADC analog input value [0 to 65536] - voltage_value = 3.3*adc_value/65536; // Read and convert to voltage the analog input value [0.0 to 3.3] + adc_value = analog_sensor.read_u16(); // Read the ADC analog input value [0 to 65535] + voltage_value = 3.3*adc_value/65535; // Read and convert to voltage the analog input value [0.0 to 3.3] percent_value = analog_sensor.read(); // Read the percent analog input value [0.0 to 1.0] printf("\n"); // Serial new line printf("Analog Read: "); // Show the text between " " - printf("ADC [%d], ", adc_value); // Show the voltage value [0 to 65536] + printf("ADC [%d], ", adc_value); // Show the voltage value [0 to 65535] printf("Voltage [%f], ", voltage_value); // Show the voltage value [0.0 to 3.3] printf("Percent [%f] ", percent_value); // Show the percent value [0.0 to 1.0]