api / mbed / trunk / AnalogIn

AnalogIn

class AnalogIn : public Base

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());
        }
    }
}
AnalogInAn analog input, used for reading the voltage on a pin
Functions
AnalogInCreate an AnalogIn, connected to the specified pin
readRead the input voltage, represented as a float in the range [0.0, 1.0]
read_u16Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
operator floatAn operator shorthand for read()

Functions

AnalogIn

AnalogIn(PinName pin,  
const char *name =  NULL)

Create an AnalogIn, connected to the specified pin

Variables

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

read

float read()

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

Variables

returnsA floating-point value representing the current input voltage, measured as a percentage

read_u16

unsigned short read_u16()

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

Variables

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

operator float

operator float()

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) { ... }
class AnalogIn : public Base
An analog input, used for reading the voltage on a pin
AnalogIn(PinName pin,  
const char *name =  NULL)
Create an AnalogIn, connected to the specified pin
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]
operator float()
An operator shorthand for read()