Programme d'utilisation des AX12 avec rajout de l'MX12

Fork of test_carteAToutFaire_PR by CRAC Team

Committer:
ClementBreteau
Date:
Thu May 11 11:49:50 2017 +0000
Revision:
1:f3f702086a30
test de la carte ? tout faire du petit robot

Who changed what in which revision?

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