Code for part 2 of lab 2

Fork of digitalInInterrupt_sample by William Marsh

Files at this revision

API Documentation at this revision

Comitter:
Tobden
Date:
Fri Feb 02 12:13:38 2018 +0000
Parent:
4:46bd7e19daae
Commit message:
Interrupt program for Mbed for switching between blinking light and pause state

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 46bd7e19daae -r 3e5e109868b6 main.cpp
--- a/main.cpp	Wed Jan 31 15:15:35 2018 +0000
+++ b/main.cpp	Fri Feb 02 12:13:38 2018 +0000
@@ -6,8 +6,8 @@
 //    is pressed
 // The callback uses a shared variable to signal another thread
 
-InterruptIn button(PTD2);
-InterruptIn button2(PTD5);
+InterruptIn button(PTD0); 
+InterruptIn button2(PTD2);
 DigitalOut led(LED_RED);
 DigitalOut led2(LED_BLUE);
 
@@ -19,10 +19,10 @@
 // This function is invoked when then interrupt occurs
 //   Signal that the button has been pressed
 //   Note: bounce may occur 
-void buttonCallback(){
+void buttonCallback(){ //Callback for the first button
     pressEvent = 1 ;
 }
-void button2Callback(){
+void button2Callback(){ //Callback for the second button
     pressEvent2 = 1;
     }
 
@@ -34,26 +34,26 @@
     button.fall(&buttonCallback) ;   // Attach function to falling edge
     button2.mode(PullUp);
     button2.fall(&button2Callback);
-    
+//led2 = 1;      
 
     while(true) {
         // Toggle the LED every time the button is pressed
         if (pressEvent) {
             change = !change;
             if (change == 1){
-            led = !led;}
+            led = led;}
             pressEvent = 0 ; // Clear the event variable
         }
-       else if (pressEvent2) {
+        if (pressEvent2) {
             change2=!change2;
             if(change2 == 1){
-            led2 = !led2;}
+            led2 = led2;}
             pressEvent2 = 0;
             }
         if (change == 0){
         led = !led ;}
-      else  if (change2 == 0){
+        if (change2 == 0){
         led2 = !led2;}
         Thread::wait(500);
     }
-}
\ No newline at end of file
+} 
\ No newline at end of file