Mbed OS Reference
Loading...
Searching...
No Matches
AnalogOut Class Reference

An analog output, used for setting the voltage on a pin. More...

#include <AnalogOut.h>

Public Member Functions

 AnalogOut (PinName pin)
 Create an AnalogOut connected to the specified pin. More...
 
 AnalogOut (const PinMap &pinmap)
 Create an AnalogOut connected to the specified pin. More...
 
void write (float value)
 Set the output voltage, specified as a percentage (float) More...
 
void write_u16 (unsigned short value)
 Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]. More...
 
float read ()
 Return the current output voltage setting, measured as a percentage (float) More...
 
AnalogOutoperator= (float percent)
 An operator shorthand for write() More...
 
AnalogOutoperator= (AnalogOut &rhs)
 An operator shorthand for write() More...
 
 operator float ()
 An operator shorthand for read() More...
 
virtual ~AnalogOut ()
 

Detailed Description

An analog output, used for setting the voltage on a pin.

Note
Synchronization level: Thread safe

Example:

// Make a sawtooth output
#include "mbed.h"
AnalogOut tri(p18);
int main() {
while(1) {
tri = tri + 0.01;
wait_us(1);
if(tri == 1) {
tri = 0;
}
}
}
An analog output, used for setting the voltage on a pin.
Definition: AnalogOut.h:56
void wait_us(int us)
Generic wait functions.

Definition at line 56 of file AnalogOut.h.

Constructor & Destructor Documentation

◆ AnalogOut() [1/2]

AnalogOut ( PinName  pin)

Create an AnalogOut connected to the specified pin.

Parameters
pinAnalogOut pin to connect to

Definition at line 63 of file AnalogOut.h.

◆ AnalogOut() [2/2]

AnalogOut ( const PinMap pinmap)

Create an AnalogOut connected to the specified pin.

Parameters
pinmapreference to structure which holds static pinmap.

Definition at line 74 of file AnalogOut.h.

◆ ~AnalogOut()

virtual ~AnalogOut ( )
virtual

Deinitialize pin configuration.

Definition at line 136 of file AnalogOut.h.

Member Function Documentation

◆ write()

void write ( float  value)

Set the output voltage, specified as a percentage (float)

Parameters
valueA floating-point value representing the output voltage, specified as a percentage. The value should lie between 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%). Values outside this range will be saturated to 0.0f or 1.0f.

◆ write_u16()

void write_u16 ( unsigned short  value)

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

Parameters
value16-bit unsigned short representing the output voltage, normalized to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)

◆ read()

float read ( )

Return the current output voltage setting, measured as a percentage (float)

Returns
A floating-point value representing the current voltage being output on the pin, measured as a percentage. The returned value will lie between 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
Note
This value may not match exactly the value set by a previous write().

◆ operator=() [1/2]

AnalogOut & operator= ( float  percent)

An operator shorthand for write()

See also
AnalogOut::write()

Definition at line 110 of file AnalogOut.h.

◆ operator=() [2/2]

AnalogOut & operator= ( AnalogOut rhs)

An operator shorthand for write()

See also
AnalogOut::write()

Definition at line 120 of file AnalogOut.h.

◆ operator float()

operator float ( )

An operator shorthand for read()

See also
AnalogOut::read()

Definition at line 130 of file AnalogOut.h.