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 // This uses INTERRUPTS to detect a falling edge of the switch input 00004 // However, pressing and releasing the switch can result in spurious falling edges 00005 // which trigger the routine 00006 00007 //Declare functions 00008 void sw1FallingEdge(); 00009 00010 //Global Objects 00011 DigitalOut red_led(D7); 00012 DigitalOut green_led(D5); 00013 InterruptIn sw1(D4); 00014 00015 //Interrupt service routine for a rising edge (press) 00016 void sw1FallingEdge() { 00017 red_led = !red_led; //Toggle the LED 00018 } 00019 00020 //Main - only has to initialise and sleep 00021 int main() { 00022 //Initial logging message 00023 puts("START"); 00024 red_led = 0; 00025 green_led = 1; 00026 00027 //Configure interrupts, wait for first rising edge 00028 sw1.fall(&sw1FallingEdge); 00029 00030 //Main Polling Loop 00031 while (true) { 00032 00033 //Put CPU back to sleep 00034 sleep(); 00035 00036 //You can ONLY reach this point if an ISR wakes the CPU 00037 puts("ISR just woke the MPU"); 00038 00039 } //end while 00040 00041 }
Generated on Wed Jul 13 2022 07:37:07 by
1.7.2