/*############################################################# Program Name : ex1_extint_button_led Author : Grant Phillips Date Modified : 14/01/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : Example to demostrate the use of an external interrupt source and how it influences the flashing of an LED. Requirements : * STM32F4-Discovery Board Circuit : * a pushbutton connected to PE8 with a pullup resitor * a LED connected to PD8 ##############################################################*/ #include "mbed.h" InterruptIn button(PA_10); //use PA_0 as an external interrupt DigitalOut redled(PD_14); DigitalOut blueled(PD_15); /* function to be called for external interrupt (any name)*/ void toggle() { blueled = !blueled; //invert old value of blueled and write new value to blueled (ie. toggle the led) } int main() { button.rise(&toggle); //when the button goes HIGH (rise) at any time (interrupt), call the toggle function //button.fall could also be used to detect going LOW while(1) { redled = !redled; //toggle the red led //wait(1.0); //even during the 1 sec wait will the toggle function be called due to the interrupt wait(0.2); } }