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