mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Embed: (wiki syntax)

« Back to documentation index

AnalogIn Class Reference

AnalogIn Class Reference
[Drivers]

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

#include <AnalogIn.h>

Public Member Functions

 AnalogIn (PinName pin)
 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()
 AnalogIn (PinName pin)
 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()

Detailed Description

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

Note:
Synchronization level: Thread safe

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());
         }
     }
 }

Definition at line 53 of file cmsis/BUILD/mbed/drivers/AnalogIn.h.


Constructor & Destructor Documentation

AnalogIn ( PinName  pin )

Create an AnalogIn, connected to the specified pin.

Parameters:
pinAnalogIn pin to connect to

Definition at line 61 of file cmsis/BUILD/mbed/drivers/AnalogIn.h.

AnalogIn ( PinName  pin )

Create an AnalogIn, connected to the specified pin.

Parameters:
pinAnalogIn pin to connect to

Definition at line 61 of file drivers/AnalogIn.h.


Member Function Documentation

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) { ... }

Definition at line 106 of file cmsis/BUILD/mbed/drivers/AnalogIn.h.

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) { ... }

Definition at line 106 of file drivers/AnalogIn.h.

float read (  )

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

Definition at line 72 of file cmsis/BUILD/mbed/drivers/AnalogIn.h.

float read ( void   )

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

Definition at line 72 of file drivers/AnalogIn.h.

unsigned short read_u16 (  )

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

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

Definition at line 85 of file cmsis/BUILD/mbed/drivers/AnalogIn.h.

unsigned short read_u16 (  )

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

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

Definition at line 85 of file drivers/AnalogIn.h.