InterruptIn demonstration based on T &W's Example 9.1

Dependencies:   mbed

main.cpp

Committer:
CSTritt
Date:
2017-10-09
Revision:
1:e731e5467ab1
Parent:
0:3151531e9a31

File content as of revision 1:e731e5467ab1:

/*
    Project: TW_Ex_9_1
    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/6/17 (v. 1.1)
*/
#include "mbed.h"

InterruptIn myButton(USER_BUTTON); // Button is normally high. Goes low w/press.

DigitalOut bluLED(D4); // Bluee 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() {
    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.
        wait(0.5); // Pause half a second.
    }
}