Dependencies:   mbed

Fork of Nucleo-ADC_with_UART_output by Cortex Challenge Team

main.cpp

Committer:
Foxnec
Date:
2015-03-05
Revision:
0:dade2710823b
Child:
1:59ea769dee88

File content as of revision 0:dade2710823b:

#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
        
    }
}