Programme d'utilisation des AX12 avec rajout de l'MX12
Fork of test_carteAToutFaire_PR by
mbed/PwmOut.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 - PwmOut |
ClementBreteau | 1:f3f702086a30 | 2 | * Copyright (c) 2007-2011 ARM Limited. All rights reserved. |
ClementBreteau | 1:f3f702086a30 | 3 | */ |
ClementBreteau | 1:f3f702086a30 | 4 | |
ClementBreteau | 1:f3f702086a30 | 5 | #ifndef MBED_PWMOUT_H |
ClementBreteau | 1:f3f702086a30 | 6 | #define MBED_PWMOUT_H |
ClementBreteau | 1:f3f702086a30 | 7 | |
ClementBreteau | 1:f3f702086a30 | 8 | #include "device.h" |
ClementBreteau | 1:f3f702086a30 | 9 | |
ClementBreteau | 1:f3f702086a30 | 10 | #if DEVICE_PWMOUT |
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: PwmOut |
ClementBreteau | 1:f3f702086a30 | 20 | * A pulse-width modulation digital output |
ClementBreteau | 1:f3f702086a30 | 21 | * |
ClementBreteau | 1:f3f702086a30 | 22 | * Example |
ClementBreteau | 1:f3f702086a30 | 23 | * > // Fade a led on. |
ClementBreteau | 1:f3f702086a30 | 24 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 25 | * > |
ClementBreteau | 1:f3f702086a30 | 26 | * > PwmOut led(LED1); |
ClementBreteau | 1:f3f702086a30 | 27 | * > |
ClementBreteau | 1:f3f702086a30 | 28 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 29 | * > while(1) { |
ClementBreteau | 1:f3f702086a30 | 30 | * > led = led + 0.01; |
ClementBreteau | 1:f3f702086a30 | 31 | * > wait(0.2); |
ClementBreteau | 1:f3f702086a30 | 32 | * > if(led == 1.0) { |
ClementBreteau | 1:f3f702086a30 | 33 | * > led = 0; |
ClementBreteau | 1:f3f702086a30 | 34 | * > } |
ClementBreteau | 1:f3f702086a30 | 35 | * > } |
ClementBreteau | 1:f3f702086a30 | 36 | * > } |
ClementBreteau | 1:f3f702086a30 | 37 | * |
ClementBreteau | 1:f3f702086a30 | 38 | * Note that on the LPC1768 and LPC2368, the PWMs all share the same |
ClementBreteau | 1:f3f702086a30 | 39 | * period - if you change the period for one, you change it for all. |
ClementBreteau | 1:f3f702086a30 | 40 | * Although routines that change the period maintain the duty cycle |
ClementBreteau | 1:f3f702086a30 | 41 | * for its PWM, all other PWMs will require their duty cycle to be |
ClementBreteau | 1:f3f702086a30 | 42 | * refreshed. |
ClementBreteau | 1:f3f702086a30 | 43 | */ |
ClementBreteau | 1:f3f702086a30 | 44 | class PwmOut : public Base { |
ClementBreteau | 1:f3f702086a30 | 45 | |
ClementBreteau | 1:f3f702086a30 | 46 | public: |
ClementBreteau | 1:f3f702086a30 | 47 | |
ClementBreteau | 1:f3f702086a30 | 48 | /* Constructor: PwmOut |
ClementBreteau | 1:f3f702086a30 | 49 | * Create a PwmOut connected to the specified pin |
ClementBreteau | 1:f3f702086a30 | 50 | * |
ClementBreteau | 1:f3f702086a30 | 51 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 52 | * pin - PwmOut pin to connect to |
ClementBreteau | 1:f3f702086a30 | 53 | */ |
ClementBreteau | 1:f3f702086a30 | 54 | PwmOut(PinName pin, const char *name = NULL); |
ClementBreteau | 1:f3f702086a30 | 55 | |
ClementBreteau | 1:f3f702086a30 | 56 | /* Function: write |
ClementBreteau | 1:f3f702086a30 | 57 | * Set the ouput duty-cycle, specified as a percentage (float) |
ClementBreteau | 1:f3f702086a30 | 58 | * |
ClementBreteau | 1:f3f702086a30 | 59 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 60 | * value - A floating-point value representing the output duty-cycle, |
ClementBreteau | 1:f3f702086a30 | 61 | * specified as a percentage. The value should lie between |
ClementBreteau | 1:f3f702086a30 | 62 | * 0.0f (representing on 0%) and 1.0f (representing on 100%). |
ClementBreteau | 1:f3f702086a30 | 63 | * Values outside this range will be saturated to 0.0f or 1.0f. |
ClementBreteau | 1:f3f702086a30 | 64 | */ |
ClementBreteau | 1:f3f702086a30 | 65 | void write(float value); |
ClementBreteau | 1:f3f702086a30 | 66 | |
ClementBreteau | 1:f3f702086a30 | 67 | /* Function: read |
ClementBreteau | 1:f3f702086a30 | 68 | * Return the current output duty-cycle setting, measured as a percentage (float) |
ClementBreteau | 1:f3f702086a30 | 69 | * |
ClementBreteau | 1:f3f702086a30 | 70 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 71 | * returns - A floating-point value representing the current duty-cycle being output on the pin, |
ClementBreteau | 1:f3f702086a30 | 72 | * measured as a percentage. The returned value will lie between |
ClementBreteau | 1:f3f702086a30 | 73 | * 0.0f (representing on 0%) and 1.0f (representing on 100%). |
ClementBreteau | 1:f3f702086a30 | 74 | * |
ClementBreteau | 1:f3f702086a30 | 75 | * Note: |
ClementBreteau | 1:f3f702086a30 | 76 | * This value may not match exactly the value set by a previous <write>. |
ClementBreteau | 1:f3f702086a30 | 77 | */ |
ClementBreteau | 1:f3f702086a30 | 78 | float read(); |
ClementBreteau | 1:f3f702086a30 | 79 | |
ClementBreteau | 1:f3f702086a30 | 80 | /* Function: period |
ClementBreteau | 1:f3f702086a30 | 81 | * Set the PWM period, specified in seconds (float), keeping the |
ClementBreteau | 1:f3f702086a30 | 82 | * duty cycle the same. |
ClementBreteau | 1:f3f702086a30 | 83 | * |
ClementBreteau | 1:f3f702086a30 | 84 | * Note: |
ClementBreteau | 1:f3f702086a30 | 85 | * The resolution is currently in microseconds; periods smaller than this |
ClementBreteau | 1:f3f702086a30 | 86 | * will be set to zero. |
ClementBreteau | 1:f3f702086a30 | 87 | */ |
ClementBreteau | 1:f3f702086a30 | 88 | void period(float seconds); |
ClementBreteau | 1:f3f702086a30 | 89 | |
ClementBreteau | 1:f3f702086a30 | 90 | /* Function: period_ms |
ClementBreteau | 1:f3f702086a30 | 91 | * Set the PWM period, specified in milli-seconds (int), keeping the |
ClementBreteau | 1:f3f702086a30 | 92 | * duty cycle the same. |
ClementBreteau | 1:f3f702086a30 | 93 | */ |
ClementBreteau | 1:f3f702086a30 | 94 | void period_ms(int ms); |
ClementBreteau | 1:f3f702086a30 | 95 | |
ClementBreteau | 1:f3f702086a30 | 96 | /* Function: period_us |
ClementBreteau | 1:f3f702086a30 | 97 | * Set the PWM period, specified in micro-seconds (int), keeping the |
ClementBreteau | 1:f3f702086a30 | 98 | * duty cycle the same. |
ClementBreteau | 1:f3f702086a30 | 99 | */ |
ClementBreteau | 1:f3f702086a30 | 100 | void period_us(int us); |
ClementBreteau | 1:f3f702086a30 | 101 | |
ClementBreteau | 1:f3f702086a30 | 102 | /* Function: pulsewidth |
ClementBreteau | 1:f3f702086a30 | 103 | * Set the PWM pulsewidth, specified in seconds (float), keeping the |
ClementBreteau | 1:f3f702086a30 | 104 | * period the same. |
ClementBreteau | 1:f3f702086a30 | 105 | */ |
ClementBreteau | 1:f3f702086a30 | 106 | void pulsewidth(float seconds); |
ClementBreteau | 1:f3f702086a30 | 107 | |
ClementBreteau | 1:f3f702086a30 | 108 | /* Function: pulsewidth_ms |
ClementBreteau | 1:f3f702086a30 | 109 | * Set the PWM pulsewidth, specified in milli-seconds (int), keeping |
ClementBreteau | 1:f3f702086a30 | 110 | * the period the same. |
ClementBreteau | 1:f3f702086a30 | 111 | */ |
ClementBreteau | 1:f3f702086a30 | 112 | void pulsewidth_ms(int ms); |
ClementBreteau | 1:f3f702086a30 | 113 | |
ClementBreteau | 1:f3f702086a30 | 114 | /* Function: pulsewidth_us |
ClementBreteau | 1:f3f702086a30 | 115 | * Set the PWM pulsewidth, specified in micro-seconds (int), keeping |
ClementBreteau | 1:f3f702086a30 | 116 | * the period the same. |
ClementBreteau | 1:f3f702086a30 | 117 | */ |
ClementBreteau | 1:f3f702086a30 | 118 | void pulsewidth_us(int us); |
ClementBreteau | 1:f3f702086a30 | 119 | |
ClementBreteau | 1:f3f702086a30 | 120 | #ifdef MBED_OPERATORS |
ClementBreteau | 1:f3f702086a30 | 121 | /* Function: operator= |
ClementBreteau | 1:f3f702086a30 | 122 | * A operator shorthand for <write()> |
ClementBreteau | 1:f3f702086a30 | 123 | */ |
ClementBreteau | 1:f3f702086a30 | 124 | PwmOut& operator= (float value); |
ClementBreteau | 1:f3f702086a30 | 125 | PwmOut& operator= (PwmOut& rhs); |
ClementBreteau | 1:f3f702086a30 | 126 | |
ClementBreteau | 1:f3f702086a30 | 127 | /* Function: operator float() |
ClementBreteau | 1:f3f702086a30 | 128 | * An operator shorthand for <read()> |
ClementBreteau | 1:f3f702086a30 | 129 | */ |
ClementBreteau | 1:f3f702086a30 | 130 | operator float(); |
ClementBreteau | 1:f3f702086a30 | 131 | #endif |
ClementBreteau | 1:f3f702086a30 | 132 | |
ClementBreteau | 1:f3f702086a30 | 133 | #ifdef MBED_RPC |
ClementBreteau | 1:f3f702086a30 | 134 | virtual const struct rpc_method *get_rpc_methods(); |
ClementBreteau | 1:f3f702086a30 | 135 | static struct rpc_class *get_rpc_class(); |
ClementBreteau | 1:f3f702086a30 | 136 | #endif |
ClementBreteau | 1:f3f702086a30 | 137 | |
ClementBreteau | 1:f3f702086a30 | 138 | protected: |
ClementBreteau | 1:f3f702086a30 | 139 | |
ClementBreteau | 1:f3f702086a30 | 140 | PWMName _pwm; |
ClementBreteau | 1:f3f702086a30 | 141 | |
ClementBreteau | 1:f3f702086a30 | 142 | }; |
ClementBreteau | 1:f3f702086a30 | 143 | |
ClementBreteau | 1:f3f702086a30 | 144 | } // namespace mbed |
ClementBreteau | 1:f3f702086a30 | 145 | |
ClementBreteau | 1:f3f702086a30 | 146 | #endif |
ClementBreteau | 1:f3f702086a30 | 147 | |
ClementBreteau | 1:f3f702086a30 | 148 | #endif |