diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2012-09-03 18:29:45 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2012-09-03 18:29:45 -0400 |
commit | 5a5aee7906b5c11a38d2a71fc2e8849f2afae4bc (patch) | |
tree | dfbbf24f499ca6dee1ad40a4639a196d502805c4 /examples/exti-interrupt.cpp | |
parent | 359117bc2009a9302884f61b0b359bb1723ee0bd (diff) | |
parent | 9b8d7c508f9ff0633b5ab8acf9e64bee891604dc (diff) | |
download | librambutan-5a5aee7906b5c11a38d2a71fc2e8849f2afae4bc.tar.gz librambutan-5a5aee7906b5c11a38d2a71fc2e8849f2afae4bc.zip |
Merge branch 'callback_interrupt_handlers'
Diffstat (limited to 'examples/exti-interrupt.cpp')
-rw-r--r-- | examples/exti-interrupt.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/exti-interrupt.cpp b/examples/exti-interrupt.cpp new file mode 100644 index 0000000..89382d7 --- /dev/null +++ b/examples/exti-interrupt.cpp @@ -0,0 +1,50 @@ +// Toggles the built-in LED when the built in button +// on the Maple is pushed in. This uses the attachInterrupt function to +// setup the interrupt handler for the button being pressed. +// +// More about attachInterrupt: +// http://leaflabs.com/docs/lang/api/attachinterrupt.html +// + +#include <wirish/wirish.h> + +// LED is off by default +bool isLEDOn = false; + +// Interrupt handler takes in nothing and returns nothing. +void interruptHandler() { + // Set LED + isLEDOn = !isLEDOn; + digitalWrite(BOARD_LED_PIN, isLEDOn); + + // Delay slightly for switch debouncing. + delay(20); +} + +// Setup pin modes and the interrupt handler +void setup() { + pinMode(BOARD_BUTTON_PIN, INPUT); + pinMode(BOARD_LED_PIN, OUTPUT); + + attachInterrupt(BOARD_BUTTON_PIN, interruptHandler, RISING); +} + +// Loop. Does nothing in this example. +void loop() { + +} + +// Force init to be called *first*, i.e. before static object allocation. +// Otherwise, statically allocated objects that need libmaple may fail. +__attribute__((constructor)) void premain() { + init(); +} + +int main(void) { + setup(); + + while (true) { + loop(); + } + return 0; +} |