Lab 2 Part 4 - Interrupt Modified

Fork of digitalInInterrupt_sample by William Marsh

Revision:
4:58cf361db287
Parent:
3:05b6a1431a6b
--- a/main.cpp	Tue Jan 16 18:14:21 2018 +0000
+++ b/main.cpp	Fri Feb 02 17:18:38 2018 +0000
@@ -7,10 +7,14 @@
 // The callback uses a shared variable to signal another thread
 
 InterruptIn button(PTD0);
-DigitalOut led(LED_GREEN);
+InterruptIn button2(PTD5);
+DigitalOut led(LED_BLUE);
+DigitalOut led1(LED_RED);
 
 volatile int pressEvent = 0 ;
-
+volatile int pressEvent2 = 0;
+volatile int x = 0;
+volatile int y = 0;
 // This function is invoked when then interrupt occurs
 //   Signal that the button has been pressed
 //   Note: bounce may occur 
@@ -18,19 +22,48 @@
     pressEvent = 1 ;
 }
 
+
+
+// This function is invoked when then interrupt occurs
+//   Signal that the button has been pressed
+//   Note: bounce may occur 
+void button2Callback(){
+    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
-
-    while(true) {
+    button2.mode(PullUp);
+    button2.fall(&button2Callback);
+   
+    while(true){
+    if(x==0){
+    led1=!led1;
+    }
+    else if (y==0){
+        led=!led;    
+        }
         // Toggle the LED every time the button is pressed
         if (pressEvent) {
-            led = !led ;
+            x=!x;
+            if (x==1){
+            led1 = !led1;
+            }
+            
             pressEvent = 0 ; // Clear the event variable
+         }
+     
+        else if(pressEvent2) {
+            y=!y;
+            if (y==1){
+            led = !led;
+            }
+            pressEvent2 = 0 ; // Clear the event variable
         }
-        Thread::wait(100) ;
+        Thread::wait(500);
     }
-}
\ No newline at end of file
+}