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