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
- Committer:
- CSTritt
- Date:
- 2017-10-09
- Revision:
- 2:2c03f9b6d286
- Parent:
- 1:2438293c128c
- Child:
- 3:439f58e558e5
File content as of revision 2:2c03f9b6d286:
/* Project: TimeoutEX File: main.cpp Button interrupt sets global config flag. Timeout clears it.Main program flashes red or green LED based on config status. Created by Dr. C. S. Tritt Last revised: 10/8/17 (v. 1.0) */ #include "mbed.h" void buttonISR(); // Button ISR declaration. void configOff(); // Configuration mode off declaration. InterruptIn myButton(USER_BUTTON); // Button is normally high. Goes low w/press. Timeout configTime; // TimeOut constructor takes no arguments. DigitalOut redLED(D2); // Red and green LED junctions. DigitalOut grnLED(D3); bool config = false; // Configuration mode flag. int main() { redLED = 0; // Turn red & green off at start. grnLED = 0; myButton.fall(&buttonISR); // Register ISR routine. while(true) { // Main loop. if (config) { redLED = !redLED; // Toggle red junction. } else { grnLED = !grnLED; // Toggle green junction. } wait(0.5); // Pause half a second. } } void buttonISR() { // Sets config status when button falls. config = true; // Set config status. grnLED = 0; // Force green junction off. redLED = 1; // Turn red junction on. configTime.attach(&configOff, 5.0f); // Register callback. 5 sec. delay. } void configOff() { // Clears config flag after timeout. config = false; // Clear config flag. redLED = 0; // Force red junction off. grnLED = 1; // Turn green junction on. }