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.
Fork of TimeoutEx by
main.cpp@0:3151531e9a31, 2017-10-06 (annotated)
- Committer:
- CSTritt
- Date:
- Fri Oct 06 21:08:45 2017 +0000
- Revision:
- 0:3151531e9a31
- Child:
- 1:2438293c128c
Initial version of my version of T & W's Example 9.1 InterruptIn demonstration.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 0:3151531e9a31 | 1 | /* |
CSTritt | 0:3151531e9a31 | 2 | Project: TW_Ex_9_1 |
CSTritt | 0:3151531e9a31 | 3 | File: main.cpp |
CSTritt | 0:3151531e9a31 | 4 | |
CSTritt | 0:3151531e9a31 | 5 | An example similar to T&W example 9.1. Green junction will flash |
CSTritt | 0:3151531e9a31 | 6 | continuously. Blue junction will toggle in response to depressing the user |
CSTritt | 0:3151531e9a31 | 7 | button. |
CSTritt | 0:3151531e9a31 | 8 | |
CSTritt | 0:3151531e9a31 | 9 | Created by Dr. C. S. Tritt |
CSTritt | 0:3151531e9a31 | 10 | Last revised: 10/6/17 (v. 1.0) |
CSTritt | 0:3151531e9a31 | 11 | */ |
CSTritt | 0:3151531e9a31 | 12 | #include "mbed.h" |
CSTritt | 0:3151531e9a31 | 13 | |
CSTritt | 0:3151531e9a31 | 14 | InterruptIn myButton(USER_BUTTON); // Button is normally high. Goes low w/press. |
CSTritt | 0:3151531e9a31 | 15 | |
CSTritt | 0:3151531e9a31 | 16 | DigitalOut bluLED(D4); // Bluee and green LED junctions. |
CSTritt | 0:3151531e9a31 | 17 | DigitalOut grnLED(D3); |
CSTritt | 0:3151531e9a31 | 18 | |
CSTritt | 0:3151531e9a31 | 19 | void myISR() { // Simple ISR toggles the red LED junction when called. |
CSTritt | 0:3151531e9a31 | 20 | bluLED = !bluLED; // Toggle blue junction. |
CSTritt | 0:3151531e9a31 | 21 | } |
CSTritt | 0:3151531e9a31 | 22 | |
CSTritt | 0:3151531e9a31 | 23 | int main() { |
CSTritt | 0:3151531e9a31 | 24 | bluLED = 0; // Turn blue & green off at start. |
CSTritt | 0:3151531e9a31 | 25 | grnLED = 0; |
CSTritt | 0:3151531e9a31 | 26 | |
CSTritt | 0:3151531e9a31 | 27 | myButton.fall(&myISR); // "Register" the ISR routine. Sets vector. |
CSTritt | 0:3151531e9a31 | 28 | |
CSTritt | 0:3151531e9a31 | 29 | while(true) { |
CSTritt | 0:3151531e9a31 | 30 | grnLED = !grnLED; // Toggle green junction. |
CSTritt | 0:3151531e9a31 | 31 | wait(0.5); // Pause half a second. |
CSTritt | 0:3151531e9a31 | 32 | } |
CSTritt | 0:3151531e9a31 | 33 | } |