Dependencies: mbed
Fork of Nucleo-ADC_with_UART_output by
Diff: main.cpp
- Revision:
- 0:dade2710823b
- Child:
- 1:59ea769dee88
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 05 22:54:26 2015 +0000 @@ -0,0 +1,33 @@ +#include "mbed.h" + +//Nucleo F103,F303,F411 compatible + +AnalogIn analog_value(A0); + +Serial pc(SERIAL_TX, SERIAL_RX); + +DigitalOut myled(LED1); + +// Calculate the corresponding acquisition measure for a given value in mV +#define rawmeas(x) ((0xFFFF*x)/3300) +// Calculate the corresponding mV value from measured voltage +#define mv(x) ((x*3300)/0xFFFF) + +int main() { + + pc.baud(115200); + + while(1) { + uint16_t meas = analog_value.read_u16(); // Converts and read the analog input value + if (meas > rawmeas(1000)) { // If the value is greater than 1000 mV toggle the LED + myled = !myled; + } + + //Prints the measured value in millivolts + pc.printf("Measured value: %d\n", meas); + pc.printf("%d mV\n", mv(meas)); + + wait(1); // 200 ms + + } +}