![](/media/cache/profiles/Headshot_Fall2023_Square.jpg.50x50_q85.jpg)
Initial Mbed v. 5 version. Demonstrates ISR using two LED junctions, one blinking and one toggling.
main.cpp@108:5621bbcc10f5, 2021-10-17 (annotated)
- Committer:
- CSTritt
- Date:
- Sun Oct 17 15:29:28 2021 +0000
- Revision:
- 108:5621bbcc10f5
- Parent:
- 107:61b9c99a4e27
- Child:
- 109:e9badabfd93d
Initial v5 version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 107:61b9c99a4e27 | 1 | /* |
CSTritt | 108:5621bbcc10f5 | 2 | Project: 21_TW_Ex_9_1_v5 |
CSTritt | 108:5621bbcc10f5 | 3 | File: main.cpp |
CSTritt | 108:5621bbcc10f5 | 4 | |
CSTritt | 108:5621bbcc10f5 | 5 | An example similar to T&W example 9.1. Green junction will flash |
CSTritt | 108:5621bbcc10f5 | 6 | continuously. Blue junction will toggle in response to depressing the user |
CSTritt | 108:5621bbcc10f5 | 7 | button. |
CSTritt | 108:5621bbcc10f5 | 8 | |
CSTritt | 108:5621bbcc10f5 | 9 | Created by Dr. C. S. Tritt |
CSTritt | 108:5621bbcc10f5 | 10 | Last revised: 10/17/21 (v. 1.0) |
CSTritt | 107:61b9c99a4e27 | 11 | */ |
Jonathan Austin |
0:2757d7abb7d9 | 12 | #include "mbed.h" |
CSTritt | 108:5621bbcc10f5 | 13 | |
CSTritt | 108:5621bbcc10f5 | 14 | InterruptIn myButton(USER_BUTTON); // Button is normally high. Goes low w/press. |
CSTritt | 108:5621bbcc10f5 | 15 | |
CSTritt | 108:5621bbcc10f5 | 16 | DigitalOut bluLED(D4); // Blue and green LED junctions. |
CSTritt | 108:5621bbcc10f5 | 17 | DigitalOut grnLED(D3); |
CSTritt | 108:5621bbcc10f5 | 18 | |
CSTritt | 108:5621bbcc10f5 | 19 | void myISR() { // Simple ISR toggles the blue LED junction when called. |
CSTritt | 108:5621bbcc10f5 | 20 | bluLED = !bluLED; // Toggle blue junction. |
CSTritt | 108:5621bbcc10f5 | 21 | } |
CSTritt | 108:5621bbcc10f5 | 22 | |
CSTritt | 108:5621bbcc10f5 | 23 | int main() { |
CSTritt | 108:5621bbcc10f5 | 24 | const int GRN_PERIOD = 500; |
CSTritt | 108:5621bbcc10f5 | 25 | bluLED = 0; // Turn blue & green off at start. |
CSTritt | 108:5621bbcc10f5 | 26 | grnLED = 0; |
CSTritt | 108:5621bbcc10f5 | 27 | |
CSTritt | 108:5621bbcc10f5 | 28 | myButton.fall(&myISR); // "Register" the ISR routine. Sets vector. |
CSTritt | 108:5621bbcc10f5 | 29 | |
CSTritt | 108:5621bbcc10f5 | 30 | while(true) { |
CSTritt | 108:5621bbcc10f5 | 31 | grnLED = !grnLED; // Toggle green junction. |
CSTritt | 108:5621bbcc10f5 | 32 | ThisThread::sleep_for(GRN_PERIOD); // Sleep for GRN_PERIOD mS. |
CSTritt | 108:5621bbcc10f5 | 33 | } |
CSTritt | 108:5621bbcc10f5 | 34 | } |