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