Initial Mbed v. 5 version. Demonstrates ISR using two LED junctions, one blinking and one toggling.

Revision:
108:5621bbcc10f5
Parent:
107:61b9c99a4e27
Child:
109:e9badabfd93d
--- a/main.cpp	Mon Sep 20 03:01:02 2021 +0000
+++ b/main.cpp	Sun Oct 17 15:29:28 2021 +0000
@@ -1,33 +1,34 @@
 /*
-  21_myBlink_v5 - Turns on an LED on and off for, repeatedly.
-  Last Revised: 9/19/21 (v. 1.0)
-  Based on mbed example. Modified by Dr. C. S. Tritt. This example code is in 
-  the public domain. 
+    Project: 21_TW_Ex_9_1_v5
+    File: main.cpp
+    
+    An example similar to T&W example 9.1. Green junction will flash 
+    continuously. Blue junction will toggle in response to depressing the user 
+    button.
+    
+    Created by Dr. C. S. Tritt
+    Last revised: 10/17/21 (v. 1.0)
 */
-//  #include is a directive that "pastes" a file into your code.
-//  Use this specific #include at the beginning of each mbed program.
-//  mbed.h contains/points to the full definitions of our simple statements.
 #include "mbed.h"
-//  Define the object board_LED to be a digital output connected to LED1,
-//  which is the little green LED built into the Nucleo board.
-DigitalOut board_LED(LED1);
-const int WAIT_ON = 1400; // On time in seconds.
-const int WAIT_OFF = 600; // Off time in seconds. 
-/*  
-    The "main" function defines your main program -- it executes as soon as
-    you program the board. Functions can return (compute and give back) a 
-    value.  The main function could return an integer error code, so it begins 
-    with int. Functions can also accept inputs.  The main function cannot 
-    however, so its round parentheses are empty.
-*/  
-int main() { // This curly brace marks the beginning of the main function.
-    // while() will repeat a set of actions as long as the statement inside
-    // its round parentheses is true. 1 is the definition of true, so
-    // while(1) and while(true) repeat forever. 
-    while(true) {   // This curly brace marks the start of the repeated actions.
-        board_LED = 1;  // Turn on LED by storing a 1 in board_LED.
-        ThisThread::sleep_for(WAIT_ON); // Int value in mS.
-        board_LED = 0;  // Turn off LED by storing a 0 in board_LED.
-        ThisThread::sleep_for(WAIT_OFF); // Int value in mS.
-    }  // end of repeated actions  
-}  // end of main function
\ No newline at end of file
+
+InterruptIn myButton(USER_BUTTON); // Button is normally high. Goes low w/press.
+
+DigitalOut bluLED(D4); // Blue and green LED junctions.
+DigitalOut grnLED(D3);
+
+void myISR() { // Simple ISR toggles the blue LED junction when called.
+    bluLED = !bluLED; // Toggle blue junction.
+}
+
+int main() {
+    const int GRN_PERIOD = 500;
+    bluLED = 0; // Turn blue & green off at start.
+    grnLED = 0; 
+    
+    myButton.fall(&myISR); // "Register" the ISR routine. Sets vector.
+    
+    while(true) {
+        grnLED = !grnLED; // Toggle green junction.
+        ThisThread::sleep_for(GRN_PERIOD); // Sleep for GRN_PERIOD mS.
+    }
+}
\ No newline at end of file