CDY version that shares functionality with Counter
Dependencies: SDFileSystem_HelloWorld mbed FATFileSystem
mbed/drivers/Timeout.h@3:c547dba5d39b, 2018-11-05 (annotated)
- Committer:
- Charles David Young
- Date:
- Mon Nov 05 09:52:17 2018 -0700
- Revision:
- 3:c547dba5d39b
- Parent:
- 0:aa13e1c335cd
debug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Charles David Young |
0:aa13e1c335cd | 1 | /* mbed Microcontroller Library |
Charles David Young |
0:aa13e1c335cd | 2 | * Copyright (c) 2006-2013 ARM Limited |
Charles David Young |
0:aa13e1c335cd | 3 | * |
Charles David Young |
0:aa13e1c335cd | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Charles David Young |
0:aa13e1c335cd | 5 | * you may not use this file except in compliance with the License. |
Charles David Young |
0:aa13e1c335cd | 6 | * You may obtain a copy of the License at |
Charles David Young |
0:aa13e1c335cd | 7 | * |
Charles David Young |
0:aa13e1c335cd | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Charles David Young |
0:aa13e1c335cd | 9 | * |
Charles David Young |
0:aa13e1c335cd | 10 | * Unless required by applicable law or agreed to in writing, software |
Charles David Young |
0:aa13e1c335cd | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Charles David Young |
0:aa13e1c335cd | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Charles David Young |
0:aa13e1c335cd | 13 | * See the License for the specific language governing permissions and |
Charles David Young |
0:aa13e1c335cd | 14 | * limitations under the License. |
Charles David Young |
0:aa13e1c335cd | 15 | */ |
Charles David Young |
0:aa13e1c335cd | 16 | #ifndef MBED_TIMEOUT_H |
Charles David Young |
0:aa13e1c335cd | 17 | #define MBED_TIMEOUT_H |
Charles David Young |
0:aa13e1c335cd | 18 | |
Charles David Young |
0:aa13e1c335cd | 19 | #include "drivers/Ticker.h" |
Charles David Young |
0:aa13e1c335cd | 20 | |
Charles David Young |
0:aa13e1c335cd | 21 | namespace mbed { |
Charles David Young |
0:aa13e1c335cd | 22 | /** \addtogroup drivers */ |
Charles David Young |
0:aa13e1c335cd | 23 | /** @{*/ |
Charles David Young |
0:aa13e1c335cd | 24 | |
Charles David Young |
0:aa13e1c335cd | 25 | /** A Timeout is used to call a function at a point in the future |
Charles David Young |
0:aa13e1c335cd | 26 | * |
Charles David Young |
0:aa13e1c335cd | 27 | * You can use as many seperate Timeout objects as you require. |
Charles David Young |
0:aa13e1c335cd | 28 | * |
Charles David Young |
0:aa13e1c335cd | 29 | * @Note Synchronization level: Interrupt safe |
Charles David Young |
0:aa13e1c335cd | 30 | * |
Charles David Young |
0:aa13e1c335cd | 31 | * Example: |
Charles David Young |
0:aa13e1c335cd | 32 | * @code |
Charles David Young |
0:aa13e1c335cd | 33 | * // Blink until timeout. |
Charles David Young |
0:aa13e1c335cd | 34 | * |
Charles David Young |
0:aa13e1c335cd | 35 | * #include "mbed.h" |
Charles David Young |
0:aa13e1c335cd | 36 | * |
Charles David Young |
0:aa13e1c335cd | 37 | * Timeout timeout; |
Charles David Young |
0:aa13e1c335cd | 38 | * DigitalOut led(LED1); |
Charles David Young |
0:aa13e1c335cd | 39 | * |
Charles David Young |
0:aa13e1c335cd | 40 | * int on = 1; |
Charles David Young |
0:aa13e1c335cd | 41 | * |
Charles David Young |
0:aa13e1c335cd | 42 | * void attimeout() { |
Charles David Young |
0:aa13e1c335cd | 43 | * on = 0; |
Charles David Young |
0:aa13e1c335cd | 44 | * } |
Charles David Young |
0:aa13e1c335cd | 45 | * |
Charles David Young |
0:aa13e1c335cd | 46 | * int main() { |
Charles David Young |
0:aa13e1c335cd | 47 | * timeout.attach(&attimeout, 5); |
Charles David Young |
0:aa13e1c335cd | 48 | * while(on) { |
Charles David Young |
0:aa13e1c335cd | 49 | * led = !led; |
Charles David Young |
0:aa13e1c335cd | 50 | * wait(0.2); |
Charles David Young |
0:aa13e1c335cd | 51 | * } |
Charles David Young |
0:aa13e1c335cd | 52 | * } |
Charles David Young |
0:aa13e1c335cd | 53 | * @endcode |
Charles David Young |
0:aa13e1c335cd | 54 | */ |
Charles David Young |
0:aa13e1c335cd | 55 | class Timeout : public Ticker { |
Charles David Young |
0:aa13e1c335cd | 56 | |
Charles David Young |
0:aa13e1c335cd | 57 | protected: |
Charles David Young |
0:aa13e1c335cd | 58 | virtual void handler(); |
Charles David Young |
0:aa13e1c335cd | 59 | }; |
Charles David Young |
0:aa13e1c335cd | 60 | |
Charles David Young |
0:aa13e1c335cd | 61 | } // namespace mbed |
Charles David Young |
0:aa13e1c335cd | 62 | |
Charles David Young |
0:aa13e1c335cd | 63 | #endif |
Charles David Young |
0:aa13e1c335cd | 64 | |
Charles David Young |
0:aa13e1c335cd | 65 | /** @}*/ |