Read an analog value using ADC

Dependencies:   mbed

main.cpp

Committer:
jose_23991
Date:
2014-09-27
Revision:
1:c501cf08e477
Parent:
0:34080419f5c6
Child:
2:fc1b61adfc11

File content as of revision 1:c501cf08e477:

/**************************************************************************/
/*                                                                        */
/*                                                                        */
/* Note: The STM32F401 has default 3.3V I/O pins (3.3V == 4096)           */    
/**************************************************************************/

#include "mbed.h"

AnalogIn analog_sensor(A0);                       // Create the analog pin object

int main()
{
    while(1)
    {      
        uint16_t meas = analog_sensor.read_u16(); // Read the analog input (return a value in the range [0,4096] / Nucleo F401RE: 12 bits ADC)
        printf("\n Analog Read: %d", meas);       // Show the value
        wait_ms(1);                               // Wait 1ms between reads for stability
    }
}