marcello pinna
/
Nucleo_read_voltage_value_via_UART
ADC Voltage Reading using a potentiometer and UART
Diff: main.cpp
- Revision:
- 1:9c04702c4c59
- Parent:
- 0:1e259b5370c2
--- a/main.cpp Thu Oct 16 12:15:25 2014 +0000 +++ b/main.cpp Fri Oct 17 16:07:17 2014 +0000 @@ -5,7 +5,7 @@ // 9600 bauds, 8-bit data, no parity //------------------------------------ -// This program reads the voltage in output from a potentiometer connect to port A0 of Nucleo STM32F302 +// This program reads the voltage in output from a potentiometer connected to port A0 of Nucleo STM32F302 Serial pc(SERIAL_TX, SERIAL_RX); AnalogIn analog_value(A0); @@ -19,17 +19,18 @@ pc.printf ("\n"); - wait(1); // Delaey 1000 ms + wait(1); // Delay 1000 ms + while(1) { - uint16_t meas = analog_value.read_u16(); // Converts and read the analog input value (range for ADC is 0-65536) + uint16_t meas = analog_value.read_u16(); // Reads the analog input value (range for ADC is 0-65536) - pc.printf("Voltage is %d", meas*5000/65536); // Reads voltage in mV + pc.printf("Voltage is %d", meas*5000/65536); // Converts reading to voltage in mV pc.printf (" mV"); pc.printf ("\r"); - wait(0.5); // Delay 500 ms + wait(0.5); // Delay 500 ms } }