Lab-2 Digital Interrupt by Edwin Kadavy

Fork of digitalInInterrupt_sample by William Marsh

Revision:
4:54ff81b0e148
Parent:
3:05b6a1431a6b
diff -r 05b6a1431a6b -r 54ff81b0e148 main.cpp
--- a/main.cpp	Tue Jan 16 18:14:21 2018 +0000
+++ b/main.cpp	Fri Feb 02 21:29:00 2018 +0000
@@ -2,35 +2,59 @@
 
 // Labs 2: Example program for using an interrupt (or callback)
 // -----------------------------------------------------------
-// A callback function (corresponding to an ISR) is called when a button 
+// A callback function (corresponding to an ISR) is called when a button
 //    is pressed
 // The callback uses a shared variable to signal another thread
 
-InterruptIn button(PTD0);
-DigitalOut led(LED_GREEN);
+InterruptIn button1(PTD0);
+InterruptIn button2(PTD2);
+DigitalOut led1(LED_RED);
+DigitalOut led2(LED_BLUE);
 
-volatile int pressEvent = 0 ;
+volatile int pressEvent1 = 0 ;
+volatile int pressEvent2 = 0 ;
 
 // This function is invoked when then interrupt occurs
 //   Signal that the button has been pressed
-//   Note: bounce may occur 
-void buttonCallback(){
-    pressEvent = 1 ;
+//   Note: bounce may occur
+void buttonCallback1()
+{
+    pressEvent1 = 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
+int main()
+{
+    button1.mode(PullUp);             // Ensure button i/p has pull up
+    button2.mode(PullUp);             // Ensure button i/p has pull up
+    button1.fall(&buttonCallback1) ;   // Attach function to falling edge
+    button2.fall(&buttonCallback2) ;   // Attach function to falling edge
 
+    bool change1=true;
+    bool change2=true;
     while(true) {
         // Toggle the LED every time the button is pressed
-        if (pressEvent) {
-            led = !led ;
-            pressEvent = 0 ; // Clear the event variable
+        if (pressEvent1) {
+            change1=!change1;
+            pressEvent1 = 0 ; // Clear the event variable
+        }
+        if (change1==true) {
+            led1 = !led1 ;
         }
-        Thread::wait(100) ;
+        if (pressEvent2) {
+            change2=!change2;
+            pressEvent2 = 0 ; // Clear the event variable
+        }
+        if (change2==true) {
+            led2 = !led2 ;
+        }
+
+        Thread::wait(500) ;
     }
-}
\ No newline at end of file
+}