ADC Voltage Reading using a potentiometer and UART

Dependencies:   mbed

main.cpp

Committer:
marpin
Date:
2014-10-17
Revision:
1:9c04702c4c59
Parent:
0:1e259b5370c2

File content as of revision 1:9c04702c4c59:

#include "mbed.h"
 
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

// 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);
 
 
int main() {
    
    pc.printf("Program test created by Marpin - October 16, 2014" );
    
    pc.printf ("\r");
    
    pc.printf ("\n");
    
    wait(1); // Delay 1000 ms
     
    while(1) {      
        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); // Converts reading to voltage in mV
        
        pc.printf (" mV");
        
        pc.printf ("\r");
        
        wait(0.5); // Delay 500 ms
        }
       
    }