source:Interfaces/AnalogOut/AnalogOut_Interfaces.png

AnalogOut

The AnalogOut Interface is used to set the voltage of an analog output pin.

Hello World!

// Create a sawtooth wave

#include "mbed.h"

AnalogOut signal(p18);

int main() {
    while(1) {
        for(float i=0.0; i<1.0; i+=0.1) {
            signal = i;
            wait(0.0001);
        }
    }
}

API

AnalogOutAn analog output, used for setting the voltage on a pin
Functions
AnalogOutCreate an AnalogOut connected to the specified pin
writeSet the output voltage, specified as a percentage (float)
write_u16Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
readReturn the current output voltage setting, measured as a percentage (float)
operator=An operator shorthand for write()
operator float()An operator shorthand for read()
class AnalogOut : public Base
An analog output, used for setting the voltage on a pin
AnalogOut(PinName pin,  
const char *name =  NULL)
Create an AnalogOut connected to the specified pin
void write(float value)
Set the output voltage, specified as a percentage (float)
void write_u16(unsigned short value)
Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
float read()
Return the current output voltage setting, measured as a percentage (float)
AnalogOut& operator= (float percent)
An operator shorthand for write()
operator float()
An operator shorthand for read()

Details

The AnalogOut Interface can be used on mbed pin p18.

The AnalogOut Interface can be used to set the voltage on the analog output pin somwhere in the range of 0.0v to 3.3v. The 0.0v to 3.3v range of the AnalogOut can be represented in software as a normalised floating point number from 0.0 to 1.0, or directly as volts or millivolts.