Hello World for InterruptIn
Fork of InterruptIn_HelloWorld by
Use
Interrupts are a way of causing a function to be called when a certain event happens. This example demonstrates calling a function when a button is pressed. Specifically on the rising edge of a button press. This can be observed by LED4 blinking as the program runs and LED1 only changing when the button is pressed.
API
API reference.
Import librarymbed
main.cpp
- Committer:
- mbed_official
- Date:
- 2013-02-15
- Revision:
- 0:7a20a6aa1f5e
- Child:
- 2:dc8472f90484
File content as of revision 0:7a20a6aa1f5e:
#include "mbed.h" InterruptIn button(p5); DigitalOut led(LED1); DigitalOut flash(LED4); void flip() { led = !led; } int main() { button.rise(&flip); // attach the address of the flip function to the rising edge while(1) { // wait around, interrupts will interrupt this! flash = !flash; wait(0.25); } }