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