Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of digitalInInterrupt_sample by
Diff: main.cpp
- Revision:
- 4:5af35f086ddd
- Parent:
- 3:05b6a1431a6b
- Child:
- 5:dd7d8fb1ad75
--- a/main.cpp Tue Jan 16 18:14:21 2018 +0000 +++ b/main.cpp Thu Feb 01 17:13:53 2018 +0000 @@ -6,10 +6,19 @@ // is pressed // The callback uses a shared variable to signal another thread + InterruptIn button(PTD0); -DigitalOut led(LED_GREEN); +DigitalOut led(LED_BLUE); +DigitalOut led2(LED_RED); +InterruptIn button2(PTD5); + + volatile int pressEvent = 0 ; +volatile int pressEvent2 = 0 ; + + bool pressed1 = false; + bool pressed2 = false; // This function is invoked when then interrupt occurs // Signal that the button has been pressed @@ -18,19 +27,37 @@ pressEvent = 1 ; } +void buttonCallback2(){ + pressEvent2 = 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 + + button2.mode(PullUp); // Ensure button i/p has pull up + button2.fall(&buttonCallback2) ; // Attach function to falling edge while(true) { // Toggle the LED every time the button is pressed if (pressEvent) { + pressEvent = 0; // Clear the event variable + pressed1 = !pressed1; + } + if (pressEvent2) { + pressEvent2= 0 ; // Clear the event variable + pressed2= !pressed2; + } + if(!pressed1) + { led = !led ; - pressEvent = 0 ; // Clear the event variable } - Thread::wait(100) ; + if(!pressed2) { + led2= !led2; + } + Thread::wait(2000) ; } } \ No newline at end of file