strat des robots

Fork of CRAC-Strat_2017 by CRAC Team

Committer:
ClementBreteau
Date:
Fri May 19 17:14:07 2017 +0000
Revision:
17:d1594579eec6
Parent:
0:ad97421fb1fb
strat du robot, 19-05-2017, 19h

Who changed what in which revision?

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