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