1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifndef MBED_ANALOGOUT_H
17 #define MBED_ANALOGOUT_H
23 #include "analogout_api.h"
27 /** An analog output, used for setting the voltage on a pin
31 * // Make a sawtooth output
51 /** Create an AnalogOut connected to the specified pin
53 * @param AnalogOut pin to connect to (18)
55 AnalogOut(PinName pin) {
56 analogout_init(&_dac, pin);
59 /** Set the output voltage, specified as a percentage (float)
61 * @param value A floating-point value representing the output voltage,
62 * specified as a percentage. The value should lie between
63 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
64 * Values outside this range will be saturated to 0.0f or 1.0f.
66 void write(float value) {
67 analogout_write(&_dac, value);
70 /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
72 * @param value 16-bit unsigned short representing the output voltage,
73 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
75 void write_u16(unsigned short value) {
76 analogout_write_u16(&_dac, value);
79 /** Return the current output voltage setting, measured as a percentage (float)
82 * A floating-point value representing the current voltage being output on the pin,
83 * measured as a percentage. The returned value will lie between
84 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
87 * This value may not match exactly the value set by a previous write().
90 return analogout_read(&_dac);
94 /** An operator shorthand for write()
96 AnalogOut& operator= (float percent) {
101 AnalogOut& operator= (AnalogOut& rhs) {
106 /** An operator shorthand for read()