Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Timeout by
Main.cpp@0:7a0f7fbc736b, 2019-01-08 (annotated)
- Committer:
- jimbaud
- Date:
- Tue Jan 08 10:23:12 2019 +0000
- Revision:
- 0:7a0f7fbc736b
- Child:
- 1:50617d33bd51
se the Timeout interface to set up an interrupt to call a function after a specified delay.; You can create any number of Timeout objects, allowing multiple outstanding interrupts at the same time.; ;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jimbaud | 0:7a0f7fbc736b | 1 | /* https://os.mbed.com/docs/v5.7/reference/timer.html |
| jimbaud | 0:7a0f7fbc736b | 2 | |
| jimbaud | 0:7a0f7fbc736b | 3 | Use the Timeout interface to set up an interrupt to call a function after a specified delay. |
| jimbaud | 0:7a0f7fbc736b | 4 | You can create any number of Timeout objects, allowing multiple outstanding interrupts at the same time. |
| jimbaud | 0:7a0f7fbc736b | 5 | Warnings and notes |
| jimbaud | 0:7a0f7fbc736b | 6 | Timers are based on 32-bit int microsecond counters, so they can only time up to a maximum of 2^31-1 microseconds (30 minutes). They are designed for times between microseconds and seconds. For longer times, you should consider the time() real time clock. |
| jimbaud | 0:7a0f7fbc736b | 7 | No blocking code in ISR: avoid any call to wait, infinite while loop or blocking calls in general. |
| jimbaud | 0:7a0f7fbc736b | 8 | No printf, malloc or new in ISR: Avoid any call to bulky library functions. In particular, certain library functions (such as printf, malloc and new) are not re-entrant, and their behavior could be corrupted when called from an ISR. |
| jimbaud | 0:7a0f7fbc736b | 9 | */ |
| jimbaud | 0:7a0f7fbc736b | 10 | |
| jimbaud | 0:7a0f7fbc736b | 11 | #include "mbed.h" |
| jimbaud | 0:7a0f7fbc736b | 12 | |
| jimbaud | 0:7a0f7fbc736b | 13 | Timeout flipper; |
| jimbaud | 0:7a0f7fbc736b | 14 | DigitalOut led1(LED1); |
| jimbaud | 0:7a0f7fbc736b | 15 | |
| jimbaud | 0:7a0f7fbc736b | 16 | void flip() { |
| jimbaud | 0:7a0f7fbc736b | 17 | led1 = !led1; |
| jimbaud | 0:7a0f7fbc736b | 18 | } |
| jimbaud | 0:7a0f7fbc736b | 19 | |
| jimbaud | 0:7a0f7fbc736b | 20 | int main() { |
| jimbaud | 0:7a0f7fbc736b | 21 | led2 = 1; |
| jimbaud | 0:7a0f7fbc736b | 22 | flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds |
| jimbaud | 0:7a0f7fbc736b | 23 | // spin in a main loop. flipper will interrupt it to call flip |
| jimbaud | 0:7a0f7fbc736b | 24 | |
| jimbaud | 0:7a0f7fbc736b | 25 | while(1) { |
| jimbaud | 0:7a0f7fbc736b | 26 | } |
| jimbaud | 0:7a0f7fbc736b | 27 | } |
