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.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 //A slight improvement - however, the pressing of the switch still registers 00004 //spurious falling edges! 00005 00006 void sw1TimeOutHandler(); 00007 void sw1FallingEdge(); 00008 00009 00010 #define EDGE_RISEN 1 00011 #define EDGE_FALLEN 0 00012 00013 //Global Objects 00014 DigitalOut red_led(D7); 00015 DigitalOut green_led(D5); 00016 InterruptIn sw1(D4); 00017 InterruptIn sw2(D3); 00018 00019 Timeout sw1TimeOut; //Used to prevent switch bounce 00020 00021 //Interrupt service routine for handling the timeout 00022 void sw1TimeOutHandler() { 00023 sw1TimeOut.detach(); //Stop the timeout counter firing 00024 sw1.fall(&sw1FallingEdge); //Now wait for a falling edge 00025 } 00026 00027 //Interrupt service routive for SW1 falling edge (release) 00028 void sw1FallingEdge() { 00029 sw1.fall(NULL); //Disable this interrupt 00030 red_led = !red_led; //Toggle LED 00031 sw1TimeOut.attach(&sw1TimeOutHandler, 0.2); //Start timeout counter 00032 } 00033 00034 //Main - only has to initialise and sleep 00035 int main() { 00036 //Initial logging message 00037 puts("START"); 00038 00039 //Initial state 00040 red_led = 0; //Set RED LED to OFF 00041 green_led = 1; 00042 00043 //Configure interrupts, wait for first rising edge 00044 sw1.fall(&sw1FallingEdge); 00045 00046 //Main Polling Loop 00047 while (true) { 00048 00049 //Put CPU back to sleep 00050 sleep(); 00051 00052 //You can ONLY reach this point if an ISR wakes the CPU 00053 puts("ISR just woke the MPU"); 00054 00055 } //end while 00056 00057 }
Generated on Thu Aug 18 2022 08:51:39 by
1.7.2