Programme d'utilisation servomotors MX12 V1

Committer:
R66Y
Date:
Fri May 19 14:32:14 2017 +0000
Revision:
0:80df663dd15e
programme pour utiliser les servomoteurs MX12.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
R66Y 0:80df663dd15e 1 /* mbed Microcontroller Library - Timeout
R66Y 0:80df663dd15e 2 * Copyright (c) 2007-2009 ARM Limited. All rights reserved.
R66Y 0:80df663dd15e 3 */
R66Y 0:80df663dd15e 4
R66Y 0:80df663dd15e 5 #ifndef MBED_TIMEOUT_H
R66Y 0:80df663dd15e 6 #define MBED_TIMEOUT_H
R66Y 0:80df663dd15e 7
R66Y 0:80df663dd15e 8 #include "Ticker.h"
R66Y 0:80df663dd15e 9
R66Y 0:80df663dd15e 10 namespace mbed {
R66Y 0:80df663dd15e 11
R66Y 0:80df663dd15e 12 /* Class: Timeout
R66Y 0:80df663dd15e 13 * A Timeout is used to call a function at a point in the future
R66Y 0:80df663dd15e 14 *
R66Y 0:80df663dd15e 15 * You can use as many seperate Timeout objects as you require.
R66Y 0:80df663dd15e 16 *
R66Y 0:80df663dd15e 17 * Example:
R66Y 0:80df663dd15e 18 * > // Blink until timeout.
R66Y 0:80df663dd15e 19 * >
R66Y 0:80df663dd15e 20 * > #include "mbed.h"
R66Y 0:80df663dd15e 21 * >
R66Y 0:80df663dd15e 22 * > Timeout timeout;
R66Y 0:80df663dd15e 23 * > DigitalOut led(LED1);
R66Y 0:80df663dd15e 24 * >
R66Y 0:80df663dd15e 25 * > int on = 1;
R66Y 0:80df663dd15e 26 * >
R66Y 0:80df663dd15e 27 * > void attimeout() {
R66Y 0:80df663dd15e 28 * > on = 0;
R66Y 0:80df663dd15e 29 * > }
R66Y 0:80df663dd15e 30 * >
R66Y 0:80df663dd15e 31 * > int main() {
R66Y 0:80df663dd15e 32 * > timeout.attach(&attimeout, 5);
R66Y 0:80df663dd15e 33 * > while(on) {
R66Y 0:80df663dd15e 34 * > led = !led;
R66Y 0:80df663dd15e 35 * > wait(0.2);
R66Y 0:80df663dd15e 36 * > }
R66Y 0:80df663dd15e 37 * > }
R66Y 0:80df663dd15e 38 */
R66Y 0:80df663dd15e 39 class Timeout : public Ticker {
R66Y 0:80df663dd15e 40
R66Y 0:80df663dd15e 41 #if 0 // For documentation
R66Y 0:80df663dd15e 42
R66Y 0:80df663dd15e 43 /* Function: attach
R66Y 0:80df663dd15e 44 * Attach a function to be called by the Timeout, specifiying the delay in seconds
R66Y 0:80df663dd15e 45 *
R66Y 0:80df663dd15e 46 * Variables:
R66Y 0:80df663dd15e 47 * fptr - pointer to the function to be called
R66Y 0:80df663dd15e 48 * t - the time before the call in seconds
R66Y 0:80df663dd15e 49 */
R66Y 0:80df663dd15e 50 void attach(void (*fptr)(void), float t) {
R66Y 0:80df663dd15e 51 attach_us(fptr, t * 1000000.0f);
R66Y 0:80df663dd15e 52 }
R66Y 0:80df663dd15e 53
R66Y 0:80df663dd15e 54 /* Function: attach
R66Y 0:80df663dd15e 55 * Attach a member function to be called by the Timeout, specifiying the delay in seconds
R66Y 0:80df663dd15e 56 *
R66Y 0:80df663dd15e 57 * Variables:
R66Y 0:80df663dd15e 58 * tptr - pointer to the object to call the member function on
R66Y 0:80df663dd15e 59 * mptr - pointer to the member function to be called
R66Y 0:80df663dd15e 60 * t - the time before the calls in seconds
R66Y 0:80df663dd15e 61 */
R66Y 0:80df663dd15e 62 template<typename T>
R66Y 0:80df663dd15e 63 void attach(T* tptr, void (T::*mptr)(void), float t) {
R66Y 0:80df663dd15e 64 attach_us(tptr, mptr, t * 1000000.0f);
R66Y 0:80df663dd15e 65 }
R66Y 0:80df663dd15e 66
R66Y 0:80df663dd15e 67 /* Function: attach_us
R66Y 0:80df663dd15e 68 * Attach a function to be called by the Timeout, specifiying the delay in micro-seconds
R66Y 0:80df663dd15e 69 *
R66Y 0:80df663dd15e 70 * Variables:
R66Y 0:80df663dd15e 71 * fptr - pointer to the function to be called
R66Y 0:80df663dd15e 72 * t - the time before the call in micro-seconds
R66Y 0:80df663dd15e 73 */
R66Y 0:80df663dd15e 74 void attach_us(void (*fptr)(void), unsigned int t) {
R66Y 0:80df663dd15e 75 _function.attach(fptr);
R66Y 0:80df663dd15e 76 setup(t);
R66Y 0:80df663dd15e 77 }
R66Y 0:80df663dd15e 78
R66Y 0:80df663dd15e 79 /* Function: attach_us
R66Y 0:80df663dd15e 80 * Attach a member function to be called by the Timeout, specifiying the delay in micro-seconds
R66Y 0:80df663dd15e 81 *
R66Y 0:80df663dd15e 82 * Variables:
R66Y 0:80df663dd15e 83 * tptr - pointer to the object to call the member function on
R66Y 0:80df663dd15e 84 * mptr - pointer to the member function to be called
R66Y 0:80df663dd15e 85 * t - the time before the call in micro-seconds
R66Y 0:80df663dd15e 86 */
R66Y 0:80df663dd15e 87 template<typename T>
R66Y 0:80df663dd15e 88 void attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) {
R66Y 0:80df663dd15e 89 _function.attach(tptr, mptr);
R66Y 0:80df663dd15e 90 setup(t);
R66Y 0:80df663dd15e 91 }
R66Y 0:80df663dd15e 92
R66Y 0:80df663dd15e 93 /* Function: detach
R66Y 0:80df663dd15e 94 * Detach the function
R66Y 0:80df663dd15e 95 */
R66Y 0:80df663dd15e 96 void detach();
R66Y 0:80df663dd15e 97
R66Y 0:80df663dd15e 98 #endif
R66Y 0:80df663dd15e 99
R66Y 0:80df663dd15e 100 protected:
R66Y 0:80df663dd15e 101
R66Y 0:80df663dd15e 102 virtual void handler();
R66Y 0:80df663dd15e 103
R66Y 0:80df663dd15e 104 };
R66Y 0:80df663dd15e 105
R66Y 0:80df663dd15e 106 } // namespace mbed
R66Y 0:80df663dd15e 107
R66Y 0:80df663dd15e 108 #endif