Programme d'utilisation des AX12 avec rajout de l'MX12
Fork of test_carteAToutFaire_PR by
mbed/AnalogOut.h@3:1bb26049bdd1, 2017-05-20 (annotated)
- Committer:
- R66Y
- Date:
- Sat May 20 15:23:58 2017 +0000
- Revision:
- 3:1bb26049bdd1
- Parent:
- 1:f3f702086a30
Programme de contr?le des AX12 avec rajout de l'MX12;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ClementBreteau | 1:f3f702086a30 | 1 | /* mbed Microcontroller Library - AnalogOut |
ClementBreteau | 1:f3f702086a30 | 2 | * Copyright (c) 2006-2011 ARM Limited. All rights reserved. |
ClementBreteau | 1:f3f702086a30 | 3 | */ |
ClementBreteau | 1:f3f702086a30 | 4 | |
ClementBreteau | 1:f3f702086a30 | 5 | #ifndef MBED_ANALOGOUT_H |
ClementBreteau | 1:f3f702086a30 | 6 | #define MBED_ANALOGOUT_H |
ClementBreteau | 1:f3f702086a30 | 7 | |
ClementBreteau | 1:f3f702086a30 | 8 | #include "device.h" |
ClementBreteau | 1:f3f702086a30 | 9 | |
ClementBreteau | 1:f3f702086a30 | 10 | #if DEVICE_ANALOGOUT |
ClementBreteau | 1:f3f702086a30 | 11 | |
ClementBreteau | 1:f3f702086a30 | 12 | #include "platform.h" |
ClementBreteau | 1:f3f702086a30 | 13 | #include "PinNames.h" |
ClementBreteau | 1:f3f702086a30 | 14 | #include "PeripheralNames.h" |
ClementBreteau | 1:f3f702086a30 | 15 | #include "Base.h" |
ClementBreteau | 1:f3f702086a30 | 16 | |
ClementBreteau | 1:f3f702086a30 | 17 | namespace mbed { |
ClementBreteau | 1:f3f702086a30 | 18 | |
ClementBreteau | 1:f3f702086a30 | 19 | /* Class: AnalogOut |
ClementBreteau | 1:f3f702086a30 | 20 | * An analog output, used for setting the voltage on a pin |
ClementBreteau | 1:f3f702086a30 | 21 | * |
ClementBreteau | 1:f3f702086a30 | 22 | * Example: |
ClementBreteau | 1:f3f702086a30 | 23 | * > // Make a sawtooth output |
ClementBreteau | 1:f3f702086a30 | 24 | * > |
ClementBreteau | 1:f3f702086a30 | 25 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 26 | * > |
ClementBreteau | 1:f3f702086a30 | 27 | * > AnalogOut tri(p18); |
ClementBreteau | 1:f3f702086a30 | 28 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 29 | * > while(1) { |
ClementBreteau | 1:f3f702086a30 | 30 | * > tri = tri + 0.01; |
ClementBreteau | 1:f3f702086a30 | 31 | * > wait_us(1); |
ClementBreteau | 1:f3f702086a30 | 32 | * > if(tri == 1) { |
ClementBreteau | 1:f3f702086a30 | 33 | * > tri = 0; |
ClementBreteau | 1:f3f702086a30 | 34 | * > } |
ClementBreteau | 1:f3f702086a30 | 35 | * > } |
ClementBreteau | 1:f3f702086a30 | 36 | * > } |
ClementBreteau | 1:f3f702086a30 | 37 | */ |
ClementBreteau | 1:f3f702086a30 | 38 | class AnalogOut : public Base { |
ClementBreteau | 1:f3f702086a30 | 39 | |
ClementBreteau | 1:f3f702086a30 | 40 | public: |
ClementBreteau | 1:f3f702086a30 | 41 | |
ClementBreteau | 1:f3f702086a30 | 42 | /* Constructor: AnalogOut |
ClementBreteau | 1:f3f702086a30 | 43 | * Create an AnalogOut connected to the specified pin |
ClementBreteau | 1:f3f702086a30 | 44 | * |
ClementBreteau | 1:f3f702086a30 | 45 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 46 | * pin - AnalogOut pin to connect to (18) |
ClementBreteau | 1:f3f702086a30 | 47 | */ |
ClementBreteau | 1:f3f702086a30 | 48 | AnalogOut(PinName pin, const char *name = NULL); |
ClementBreteau | 1:f3f702086a30 | 49 | |
ClementBreteau | 1:f3f702086a30 | 50 | /* Function: write |
ClementBreteau | 1:f3f702086a30 | 51 | * Set the output voltage, specified as a percentage (float) |
ClementBreteau | 1:f3f702086a30 | 52 | * |
ClementBreteau | 1:f3f702086a30 | 53 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 54 | * percent - A floating-point value representing the output voltage, |
ClementBreteau | 1:f3f702086a30 | 55 | * specified as a percentage. The value should lie between |
ClementBreteau | 1:f3f702086a30 | 56 | * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%). |
ClementBreteau | 1:f3f702086a30 | 57 | * Values outside this range will be saturated to 0.0f or 1.0f. |
ClementBreteau | 1:f3f702086a30 | 58 | */ |
ClementBreteau | 1:f3f702086a30 | 59 | void write(float value); |
ClementBreteau | 1:f3f702086a30 | 60 | |
ClementBreteau | 1:f3f702086a30 | 61 | /* Function: write_u16 |
ClementBreteau | 1:f3f702086a30 | 62 | * Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF] |
ClementBreteau | 1:f3f702086a30 | 63 | * |
ClementBreteau | 1:f3f702086a30 | 64 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 65 | * value - 16-bit unsigned short representing the output voltage, |
ClementBreteau | 1:f3f702086a30 | 66 | * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v) |
ClementBreteau | 1:f3f702086a30 | 67 | */ |
ClementBreteau | 1:f3f702086a30 | 68 | void write_u16(unsigned short value); |
ClementBreteau | 1:f3f702086a30 | 69 | |
ClementBreteau | 1:f3f702086a30 | 70 | /* Function: read |
ClementBreteau | 1:f3f702086a30 | 71 | * Return the current output voltage setting, measured as a percentage (float) |
ClementBreteau | 1:f3f702086a30 | 72 | * |
ClementBreteau | 1:f3f702086a30 | 73 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 74 | * returns - A floating-point value representing the current voltage being output on the pin, |
ClementBreteau | 1:f3f702086a30 | 75 | * measured as a percentage. The returned value will lie between |
ClementBreteau | 1:f3f702086a30 | 76 | * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%). |
ClementBreteau | 1:f3f702086a30 | 77 | * |
ClementBreteau | 1:f3f702086a30 | 78 | * Note: |
ClementBreteau | 1:f3f702086a30 | 79 | * This value may not match exactly the value set by a previous <write>. |
ClementBreteau | 1:f3f702086a30 | 80 | */ |
ClementBreteau | 1:f3f702086a30 | 81 | float read(); |
ClementBreteau | 1:f3f702086a30 | 82 | |
ClementBreteau | 1:f3f702086a30 | 83 | |
ClementBreteau | 1:f3f702086a30 | 84 | #ifdef MBED_OPERATORS |
ClementBreteau | 1:f3f702086a30 | 85 | /* Function: operator= |
ClementBreteau | 1:f3f702086a30 | 86 | * An operator shorthand for <write()> |
ClementBreteau | 1:f3f702086a30 | 87 | */ |
ClementBreteau | 1:f3f702086a30 | 88 | AnalogOut& operator= (float percent); |
ClementBreteau | 1:f3f702086a30 | 89 | AnalogOut& operator= (AnalogOut& rhs); |
ClementBreteau | 1:f3f702086a30 | 90 | |
ClementBreteau | 1:f3f702086a30 | 91 | /* Function: operator float() |
ClementBreteau | 1:f3f702086a30 | 92 | * An operator shorthand for <read()> |
ClementBreteau | 1:f3f702086a30 | 93 | */ |
ClementBreteau | 1:f3f702086a30 | 94 | operator float(); |
ClementBreteau | 1:f3f702086a30 | 95 | #endif |
ClementBreteau | 1:f3f702086a30 | 96 | |
ClementBreteau | 1:f3f702086a30 | 97 | #ifdef MBED_RPC |
ClementBreteau | 1:f3f702086a30 | 98 | virtual const struct rpc_method *get_rpc_methods(); |
ClementBreteau | 1:f3f702086a30 | 99 | static struct rpc_class *get_rpc_class(); |
ClementBreteau | 1:f3f702086a30 | 100 | #endif |
ClementBreteau | 1:f3f702086a30 | 101 | |
ClementBreteau | 1:f3f702086a30 | 102 | protected: |
ClementBreteau | 1:f3f702086a30 | 103 | |
ClementBreteau | 1:f3f702086a30 | 104 | DACName _dac; |
ClementBreteau | 1:f3f702086a30 | 105 | |
ClementBreteau | 1:f3f702086a30 | 106 | }; |
ClementBreteau | 1:f3f702086a30 | 107 | |
ClementBreteau | 1:f3f702086a30 | 108 | } // namespace mbed |
ClementBreteau | 1:f3f702086a30 | 109 | |
ClementBreteau | 1:f3f702086a30 | 110 | #endif |
ClementBreteau | 1:f3f702086a30 | 111 | |
ClementBreteau | 1:f3f702086a30 | 112 | #endif |