lab 2 program A

Files at this revision

API Documentation at this revision

Comitter:
duncangparker
Date:
Thu Jan 24 09:53:55 2019 +0000
Parent:
4:728667196916
Commit message:
First program for lab2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 728667196916 -r 9b473d97bbf7 main.cpp
--- a/main.cpp	Tue Jan 15 10:09:53 2019 +0000
+++ b/main.cpp	Thu Jan 24 09:53:55 2019 +0000
@@ -6,31 +6,63 @@
 //    is pressed
 // The callback uses a shared variable to signal another thread
 
-InterruptIn button(PTD0);
-DigitalOut led(LED_GREEN);
+InterruptIn button_G(PTD0);
+InterruptIn button_B(PTD5);
 
-volatile int pressEvent = 0 ;
+DigitalOut led_G(LED_GREEN);
+DigitalOut led_B(LED_BLUE);
+
+volatile int pressEvent_G = 0 ;
+volatile int pressEvent_B = 0 ;
 
 // This function is invoked when then interrupt occurs
 //   Signal that the button has been pressed
 //   Note: bounce may occur 
-void buttonCallback(){
-    pressEvent = 1 ;
+void buttonCallback_G(){
+    pressEvent_G = 1 ;
+}
+
+void buttonCallback_B(){
+    pressEvent_B = 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
+    button_G.mode(PullUp);             // Ensure button i/p has pull up
+    button_G.fall(&buttonCallback_G) ;   // Attach function to falling edge
+
+    button_B.mode(PullUp);             // Ensure button i/p has pull up
+    button_B.fall(&buttonCallback_B) ;   // Attach function to falling edge
+
+    //int counter_G = 2;
+    //int rate_G = 1;
+    
+    //int counter_B = 2;
+    //int rate_B = 1;    
+    
+    bool on_G = 0;
+    bool on_B = 0;
 
     while(true) {
-        // Toggle the LED every time the button is pressed
-        if (pressEvent) {
-            led = !led ;
-            pressEvent = 0 ; // Clear the event variable
+        // Toggle the Green LED every time the button is pressed
+        if (pressEvent_G) {
+            //led_G = !led_G ;
+            pressEvent_G = 0 ; // Clear the event variable
+            on_G = !on_G;
         }
-        wait(0.1) ;
+        
+        // Toggle the Green LED every time the button is pressed
+        if (pressEvent_B) {
+            //led_B = !led_B ;
+            pressEvent_B = 0 ; // Clear the event variable
+            on_B = !on_B;
+        }
+        
+        led_G = (!led_G)|on_G;
+        led_B = (!led_B)|on_B;
+        
+        wait(0.5) ;
     }
 }
\ No newline at end of file