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