Programme d'utilisation des AX12 avec rajout de l'MX12
Fork of test_carteAToutFaire_PR by
mbed/Timer.h@1:f3f702086a30, 2017-05-11 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
ClementBreteau | 1:f3f702086a30 | 1 | /* mbed Microcontroller Library - Timer |
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_TIMER_H |
ClementBreteau | 1:f3f702086a30 | 6 | #define MBED_TIMER_H |
ClementBreteau | 1:f3f702086a30 | 7 | |
ClementBreteau | 1:f3f702086a30 | 8 | #include "platform.h" |
ClementBreteau | 1:f3f702086a30 | 9 | #include "PinNames.h" |
ClementBreteau | 1:f3f702086a30 | 10 | #include "PeripheralNames.h" |
ClementBreteau | 1:f3f702086a30 | 11 | #include "Base.h" |
ClementBreteau | 1:f3f702086a30 | 12 | |
ClementBreteau | 1:f3f702086a30 | 13 | namespace mbed { |
ClementBreteau | 1:f3f702086a30 | 14 | |
ClementBreteau | 1:f3f702086a30 | 15 | /* Class: Timer |
ClementBreteau | 1:f3f702086a30 | 16 | * A general purpose timer |
ClementBreteau | 1:f3f702086a30 | 17 | * |
ClementBreteau | 1:f3f702086a30 | 18 | * Example: |
ClementBreteau | 1:f3f702086a30 | 19 | * > // Count the time to toggle a LED |
ClementBreteau | 1:f3f702086a30 | 20 | * > |
ClementBreteau | 1:f3f702086a30 | 21 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 22 | * > |
ClementBreteau | 1:f3f702086a30 | 23 | * > Timer timer; |
ClementBreteau | 1:f3f702086a30 | 24 | * > DigitalOut led(LED1); |
ClementBreteau | 1:f3f702086a30 | 25 | * > int begin, end; |
ClementBreteau | 1:f3f702086a30 | 26 | * > |
ClementBreteau | 1:f3f702086a30 | 27 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 28 | * > timer.start(); |
ClementBreteau | 1:f3f702086a30 | 29 | * > begin = timer.read_us(); |
ClementBreteau | 1:f3f702086a30 | 30 | * > led = !led; |
ClementBreteau | 1:f3f702086a30 | 31 | * > end = timer.read_us(); |
ClementBreteau | 1:f3f702086a30 | 32 | * > printf("Toggle the led takes %d us", end - begin); |
ClementBreteau | 1:f3f702086a30 | 33 | * > } |
ClementBreteau | 1:f3f702086a30 | 34 | */ |
ClementBreteau | 1:f3f702086a30 | 35 | class Timer : public Base { |
ClementBreteau | 1:f3f702086a30 | 36 | |
ClementBreteau | 1:f3f702086a30 | 37 | public: |
ClementBreteau | 1:f3f702086a30 | 38 | |
ClementBreteau | 1:f3f702086a30 | 39 | Timer(const char *name = NULL); |
ClementBreteau | 1:f3f702086a30 | 40 | |
ClementBreteau | 1:f3f702086a30 | 41 | /* Function: start |
ClementBreteau | 1:f3f702086a30 | 42 | * Start the timer |
ClementBreteau | 1:f3f702086a30 | 43 | */ |
ClementBreteau | 1:f3f702086a30 | 44 | void start(); |
ClementBreteau | 1:f3f702086a30 | 45 | |
ClementBreteau | 1:f3f702086a30 | 46 | /* Function: stop |
ClementBreteau | 1:f3f702086a30 | 47 | * Stop the timer |
ClementBreteau | 1:f3f702086a30 | 48 | */ |
ClementBreteau | 1:f3f702086a30 | 49 | void stop(); |
ClementBreteau | 1:f3f702086a30 | 50 | |
ClementBreteau | 1:f3f702086a30 | 51 | /* Function: reset |
ClementBreteau | 1:f3f702086a30 | 52 | * Reset the timer to 0. |
ClementBreteau | 1:f3f702086a30 | 53 | * |
ClementBreteau | 1:f3f702086a30 | 54 | * If it was already counting, it will continue |
ClementBreteau | 1:f3f702086a30 | 55 | */ |
ClementBreteau | 1:f3f702086a30 | 56 | void reset(); |
ClementBreteau | 1:f3f702086a30 | 57 | |
ClementBreteau | 1:f3f702086a30 | 58 | /* Function: read |
ClementBreteau | 1:f3f702086a30 | 59 | * Get the time passed in seconds |
ClementBreteau | 1:f3f702086a30 | 60 | */ |
ClementBreteau | 1:f3f702086a30 | 61 | float read(); |
ClementBreteau | 1:f3f702086a30 | 62 | |
ClementBreteau | 1:f3f702086a30 | 63 | /* Function: read_ms |
ClementBreteau | 1:f3f702086a30 | 64 | * Get the time passed in mili-seconds |
ClementBreteau | 1:f3f702086a30 | 65 | */ |
ClementBreteau | 1:f3f702086a30 | 66 | int read_ms(); |
ClementBreteau | 1:f3f702086a30 | 67 | |
ClementBreteau | 1:f3f702086a30 | 68 | /* Function: read_us |
ClementBreteau | 1:f3f702086a30 | 69 | * Get the time passed in micro-seconds |
ClementBreteau | 1:f3f702086a30 | 70 | */ |
ClementBreteau | 1:f3f702086a30 | 71 | int read_us(); |
ClementBreteau | 1:f3f702086a30 | 72 | |
ClementBreteau | 1:f3f702086a30 | 73 | #ifdef MBED_OPERATORS |
ClementBreteau | 1:f3f702086a30 | 74 | operator float(); |
ClementBreteau | 1:f3f702086a30 | 75 | #endif |
ClementBreteau | 1:f3f702086a30 | 76 | |
ClementBreteau | 1:f3f702086a30 | 77 | #ifdef MBED_RPC |
ClementBreteau | 1:f3f702086a30 | 78 | virtual const struct rpc_method *get_rpc_methods(); |
ClementBreteau | 1:f3f702086a30 | 79 | static struct rpc_class *get_rpc_class(); |
ClementBreteau | 1:f3f702086a30 | 80 | #endif |
ClementBreteau | 1:f3f702086a30 | 81 | |
ClementBreteau | 1:f3f702086a30 | 82 | protected: |
ClementBreteau | 1:f3f702086a30 | 83 | |
ClementBreteau | 1:f3f702086a30 | 84 | int slicetime(); |
ClementBreteau | 1:f3f702086a30 | 85 | int _running; // whether the timer is running |
ClementBreteau | 1:f3f702086a30 | 86 | unsigned int _start; // the start time of the latest slice |
ClementBreteau | 1:f3f702086a30 | 87 | int _time; // any accumulated time from previous slices |
ClementBreteau | 1:f3f702086a30 | 88 | |
ClementBreteau | 1:f3f702086a30 | 89 | }; |
ClementBreteau | 1:f3f702086a30 | 90 | |
ClementBreteau | 1:f3f702086a30 | 91 | } // namespace mbed |
ClementBreteau | 1:f3f702086a30 | 92 | |
ClementBreteau | 1:f3f702086a30 | 93 | #endif |