Solution to Interrupt Exercise
Fork of digitalInInterrupt_sample by
Revision 4:60cc36256d3e, committed 2018-02-01
- Comitter:
- Sarang
- Date:
- Thu Feb 01 17:20:42 2018 +0000
- Parent:
- 3:05b6a1431a6b
- Commit message:
- Final
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 05b6a1431a6b -r 60cc36256d3e main.cpp --- a/main.cpp Tue Jan 16 18:14:21 2018 +0000 +++ b/main.cpp Thu Feb 01 17:20:42 2018 +0000 @@ -7,30 +7,71 @@ // The callback uses a shared variable to signal another thread InterruptIn button(PTD0); -DigitalOut led(LED_GREEN); +InterruptIn button1(PTD2); +DigitalOut led(LED_RED); +DigitalOut led1(LED_BLUE); volatile int pressEvent = 0 ; +volatile int pressEvent1 = 0 ; +volatile int timez = 500 ; + +volatile int buttonpressed = 1; +volatile int buttonpressed1 = 1; + // This function is invoked when then interrupt occurs // Signal that the button has been pressed // Note: bounce may occur -void buttonCallback(){ +void buttonCallback() + +{ pressEvent = 1 ; } +void buttonCallback1() + +{ + pressEvent1 = 1 ; +} + /* ---- Main function (default thread) ---- Note that if this thread completes, nothing else works */ int main() { button.mode(PullUp); // Ensure button i/p has pull up button.fall(&buttonCallback) ; // Attach function to falling edge + + button1.mode(PullUp); + button1.fall(&buttonCallback1); while(true) { // Toggle the LED every time the button is pressed + if (pressEvent) { - led = !led ; + + buttonpressed = !buttonpressed; + pressEvent = 0 ; // Clear the event variable } - Thread::wait(100) ; + + if (pressEvent1) { + + buttonpressed1 = !buttonpressed1; + + pressEvent1 = 0 ; // Clear the event variable + } + + if (buttonpressed){ + + led =!led; + } + + if (buttonpressed1){ + + led1 =!led1; + } + + + Thread::wait(timez) ; } } \ No newline at end of file