mbed-drivers
Public Member Functions | Protected Attributes | List of all members
mbed::AnalogIn Class Reference

#include <AnalogIn.h>

Public Member Functions

 AnalogIn (PinName pin)
 
float read ()
 
unsigned short read_u16 ()
 
 operator float ()
 

Protected Attributes

analogin_t _adc
 

Detailed Description

An analog input, used for reading the voltage on a pin

Example:

// Print messages when the AnalogIn is greater than 50%
#include "mbed.h"
AnalogIn temperature(p20);
int main() {
while(1) {
if(temperature > 0.5) {
printf("Too hot! (%f)", temperature.read());
}
}
}

Constructor & Destructor Documentation

mbed::AnalogIn::AnalogIn ( PinName  pin)
inline

Create an AnalogIn, connected to the specified pin

Parameters
pinAnalogIn pin to connect to
name(optional) A string to identify the object

Member Function Documentation

mbed::AnalogIn::operator float ( )
inline

An operator shorthand for read()

The float() operator can be used as a shorthand for read() to simplify common code sequences

Example:

float x = volume.read();
float x = volume;
if(volume.read() > 0.25) { ... }
if(volume > 0.25) { ... }
float mbed::AnalogIn::read ( )
inline

Read the input voltage, represented as a float in the range [0.0, 1.0]

Returns
A floating-point value representing the current input voltage, measured as a percentage
unsigned short mbed::AnalogIn::read_u16 ( )
inline

Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]

Returns
16-bit unsigned short representing the current input voltage, normalised to a 16-bit value

The documentation for this class was generated from the following file: