svn / mbed / trunk / AnalogOut.h

Revision 29, 2.6 kB (checked in by emilmont, 6 months ago)

New Libraries 11.11

Line 
1/* mbed Microcontroller Library - AnalogOut
2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
3 */ 
4 
5#ifndef MBED_ANALOGOUT_H
6#define MBED_ANALOGOUT_H
7
8#include "device.h"
9
10#if DEVICE_ANALOGOUT
11
12#include "platform.h"
13#include "PinNames.h"
14#include "PeripheralNames.h"
15#include "Base.h"
16
17namespace mbed {
18
19/* Class: AnalogOut
20 *  An analog output, used for setting the voltage on a pin
21 *
22 * Example:
23 * > // Make a sawtooth output
24 * >
25 * > #include "mbed.h"
26 * >
27 * > AnalogOut tri(p18);
28 * > int main() {
29 * >     while(1) {
30 * >         tri = tri + 0.01;
31 * >         wait_us(1);
32 * >         if(tri == 1) {
33 * >             tri = 0;
34 * >         }
35 * >     }
36 * > }
37 */
38class AnalogOut : public Base {
39
40public:
41
42    /* Constructor: AnalogOut
43     *  Create an AnalogOut connected to the specified pin
44     *
45     * Variables:
46     *  pin - AnalogOut pin to connect to (18)
47     */
48    AnalogOut(PinName pin, const char *name = NULL);
49   
50    /* Function: write
51     *  Set the output voltage, specified as a percentage (float)
52     *
53     * Variables:
54     *  percent - A floating-point value representing the output voltage,
55     *    specified as a percentage. The value should lie between
56     *    0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
57     *    Values outside this range will be saturated to 0.0f or 1.0f.   
58     */
59    void write(float value);
60   
61    /* Function: write_u16
62     *  Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
63     *
64     * Variables:
65     *  value - 16-bit unsigned short representing the output voltage,
66     *            normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
67     */
68    void write_u16(unsigned short value);
69
70    /* Function: read
71     *  Return the current output voltage setting, measured as a percentage (float)
72     *
73     * Variables:
74     *  returns - A floating-point value representing the current voltage being output on the pin,
75     *    measured as a percentage. The returned value will lie between
76     *    0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
77     *
78     * Note:
79     *  This value may not match exactly the value set by a previous <write>.
80     */ 
81    float read();
82
83
84#ifdef MBED_OPERATORS
85    /* Function: operator=
86     *  An operator shorthand for <write()>
87     */
88    AnalogOut& operator= (float percent);
89    AnalogOut& operator= (AnalogOut& rhs);
90
91    /* Function: operator float()
92     *  An operator shorthand for <read()>
93     */ 
94    operator float();
95#endif
96
97#ifdef MBED_RPC
98    virtual const struct rpc_method *get_rpc_methods();
99    static struct rpc_class *get_rpc_class();
100#endif
101
102protected:
103
104    DACName _dac;
105
106};
107
108} // namespace mbed
109
110#endif
111
112#endif
Note: See TracBrowser for help on using the browser.