svn / mbed / trunk / AnalogIn.h

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

New Libraries 11.11

Line 
1/* mbed Microcontroller Library - AnalogIn
2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
3 */ 
4
5#ifndef MBED_ANALOGIN_H
6#define MBED_ANALOGIN_H
7
8#include "device.h"
9
10#if DEVICE_ANALOGIN
11
12#include "platform.h"
13#include "PinNames.h"
14#include "PeripheralNames.h"
15#include "Base.h"
16
17namespace mbed {
18
19/* Class: AnalogIn
20 *  An analog input, used for reading the voltage on a pin
21 *
22 * Example:
23 * > // Print messages when the AnalogIn is greater than 50%
24 * >
25 * > #include "mbed.h"
26 * >
27 * > AnalogIn temperature(p20);
28 * >
29 * > int main() {
30 * >     while(1) {
31 * >         if(temperature > 0.5) {
32 * >             printf("Too hot! (%f)", temperature.read());             
33 * >         }
34 * >     }
35 * > }
36 */
37class AnalogIn :  public Base {
38
39public:
40
41    /* Constructor: AnalogIn
42     *  Create an AnalogIn, connected to the specified pin
43     *
44     * Variables:
45     *  pin - AnalogIn pin to connect to
46     *  name - (optional) A string to identify the object
47     */
48    AnalogIn(PinName pin, const char *name = NULL);
49   
50    /* Function: read
51     * Read the input voltage, represented as a float in the range [0.0, 1.0]
52     *
53     * Variables:
54     *  returns - A floating-point value representing the current input voltage,
55     *            measured as a percentage
56     */
57    float read();   
58
59    /* Function: read_u16
60     *  Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
61     *
62     * Variables:
63     *  returns - 16-bit unsigned short representing the current input voltage,
64     *            normalised to a 16-bit value
65     */
66    unsigned short read_u16();
67
68#ifdef MBED_OPERATORS
69    /* Function: operator float
70     *  An operator shorthand for <read()>
71     *
72     * The float() operator can be used as a shorthand for <read()> to simplify common code sequences
73     *
74     * Example:
75     * > float x = volume.read();
76     * > float x = volume;
77     * >
78     * > if(volume.read() > 0.25) { ... }
79     * > if(volume > 0.25) { ... }
80     */
81    operator float();
82#endif
83
84#ifdef MBED_RPC
85    virtual const struct rpc_method *get_rpc_methods();
86    static struct rpc_class *get_rpc_class();
87#endif
88
89protected:
90
91    ADCName _adc;
92   
93};
94
95} // namespace mbed
96
97#endif
98
99#endif
Note: See TracBrowser for help on using the browser.