lab 2 complete

Files at this revision

API Documentation at this revision

Comitter:
ec19664
Date:
Sat Feb 15 01:02:49 2020 +0000
Parent:
5:86742cfaf4e4
Commit message:
final lab 2 complete

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 86742cfaf4e4 -r 5df490a57e4a main.cpp
--- a/main.cpp	Thu Jan 30 08:16:04 2020 +0000
+++ b/main.cpp	Sat Feb 15 01:02:49 2020 +0000
@@ -7,15 +7,20 @@
 // The callback uses a shared variable to signal another thread
 
 InterruptIn button(PTD0);  // Pin must be on ports A or D
-DigitalOut led(LED_GREEN);
-
-volatile int pressEvent = 0 ;
+InterruptIn button1(PTD5);
+DigitalOut led(LED_RED);
+DigitalOut led5(LED_BLUE);
+volatile int pressEvent =  1;
+volatile int pressEvent1 = 1;
 
 // This function is invoked when then interrupt occurs
 //   Signal that the button has been pressed
 //   Note: bounce may occur 
 void buttonCallback(){
-    pressEvent = 1 ;  
+    pressEvent = !pressEvent ;  
+}
+void buttonCallback1(){
+    pressEvent1 = !pressEvent1 ;  
 }
 
 /*  ---- Main function (default thread) ----
@@ -24,13 +29,17 @@
 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 ;
-            pressEvent = 0 ; // Clear the event variable
         }
-        ThisThread::sleep_for(100) ; // delay for 100ms 
+        if (pressEvent1) {
+            led5 = !led5 ;
+            
+        }
+        ThisThread::sleep_for(500) ; // delay for 100ms 
     }
 }
\ No newline at end of file