An analog input, used for reading the voltage on a pin. More...
#include <AnalogIn.h>
Public Member Functions | |
AnalogIn (const PinMap &pinmap, float vref=MBED_CONF_TARGET_DEFAULT_ADC_VREF) | |
Create an AnalogIn, connected to the specified pin. More... | |
AnalogIn (PinName pin, float vref=MBED_CONF_TARGET_DEFAULT_ADC_VREF) | |
Create an AnalogIn, connected to the specified pin. More... | |
float | read () |
Read the input voltage, represented as a float in the range [0.0, 1.0]. More... | |
unsigned short | read_u16 () |
Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]. More... | |
float | read_voltage () |
Read the input voltage in volts. More... | |
void | set_reference_voltage (float vref) |
Sets this AnalogIn instance's reference voltage. More... | |
float | get_reference_voltage () const |
Gets this AnalogIn instance's reference voltage. More... | |
operator float () | |
An operator shorthand for read() More... | |
An analog input, used for reading the voltage on a pin.
Example:
Definition at line 68 of file AnalogIn.h.
Create an AnalogIn, connected to the specified pin.
pinmap | reference to structure which holds static pinmap. |
vref | (optional) Reference voltage of this AnalogIn instance (defaults to target.default-adc-vref). |
read
is called AnalogIn | ( | PinName | pin, |
float | vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF |
||
) |
float get_reference_voltage | ( | ) | const |
operator float | ( | ) |
An operator shorthand for read()
The float() operator can be used as a shorthand for read() to simplify common code sequences
Example:
Definition at line 146 of file AnalogIn.h.
float read | ( | ) |
Read the input voltage, represented as a float in the range [0.0, 1.0].
unsigned short read_u16 | ( | ) |
Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF].
float read_voltage | ( | ) |
Read the input voltage in volts.
The output depends on the target board's ADC reference voltage (typically equal to supply voltage). The ADC reference voltage sets the maximum voltage the ADC can quantify (ie: ADC output == ADC_MAX_VALUE when Vin == Vref)
The target's default ADC reference voltage is determined by the configuration option target.default-adc_vref. The reference voltage for a particular input can be manually specified by either the constructor or AnalogIn::set_reference_voltage
.