Code to demonstrate use of the two buttons to toggle LED's
Fork of nRF_buttons by
Diff: main.cpp
- Revision:
- 1:0133472f4825
- Parent:
- 0:f932320f7606
- Child:
- 2:2ee8a0e3e3f9
--- a/main.cpp Fri Dec 12 09:01:15 2014 +0000 +++ b/main.cpp Fri Dec 12 18:02:52 2014 +0000 @@ -5,30 +5,40 @@ Last Update: 12.12.2014 */ #include "mbed.h" -//Define pin names and numbers ( I know these probably aren't needed but I put them in to demonstrate pin numbers) +/* Define pin names and numbers (I know these probably aren't needed but I put them in to demonstrate pin numbering) */ #define LED1 p18 #define LED2 p19 #define SW1 p16 #define SW2 p17 +/*Function Prototypes*/ +void trigger1();//Button1 Interrupt function +void trigger2();//Button2 Interrup Function + //Instantiate IO objects DigitalOut led_1(LED1); DigitalOut led_2(LED2); DigitalIn sw_1(SW1); DigitalIn sw_2(SW2); +//Instantiate input interrupts +InterruptIn sw1Press(SW1); +InterruptIn sw2Press(SW2); int main() { + //Initialise LED output led_1=0; led_2=0; - while(1) { - if(!sw_1) - { - led_1=!led_1; - wait(0.25); //Button Debounce ;) - } - if(!sw_2) - { - led_2=!led_2; - wait(0.25); //Button Debounce ;) - } - } + //Choose falling edge interrupt and connect to apppropriate interrup function + sw1Press.fall(&trigger1); + sw2Press.fall(&trigger2); + while(1) {} } +/*Button1 interrupt function*/ +void trigger1() +{ + led_1=!led_1; +} +/*Button2 interrupt function*/ +void trigger2() +{ + led_2=!led_2; +} \ No newline at end of file