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