Lab 2 sample 2: use of interrupts

Dependents:   digitalInInterrupt_sample

Fork of digitalInPolling_sample by William Marsh

Files at this revision

API Documentation at this revision

Comitter:
WilliamMarshQMUL
Date:
Tue Jan 16 18:14:21 2018 +0000
Parent:
2:071f22412cdc
Child:
4:728667196916
Commit message:
Convert to mbed 5

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jan 24 18:31:35 2017 +0000
+++ b/main.cpp	Tue Jan 16 18:14:21 2018 +0000
@@ -1,5 +1,4 @@
 #include "mbed.h"
-#include "rtos.h"
 
 // Labs 2: Example program for using an interrupt (or callback)
 // -----------------------------------------------------------
@@ -8,32 +7,30 @@
 // The callback uses a shared variable to signal another thread
 
 InterruptIn button(PTD0);
-DigitalOut led(LED_RED);
+DigitalOut led(LED_GREEN);
 
-Thread flashT ;
 volatile int pressEvent = 0 ;
 
-// Signal when the button is pressed
+// This function is invoked when then interrupt occurs
+//   Signal that the button has been pressed
 //   Note: bounce may occur 
 void buttonCallback(){
     pressEvent = 1 ;
 }
 
-// Toggle the LED every time the button is pressed
-//    Note: the LED could be toggled in the callback 
-void flash() {
+/*  ---- 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) {
+        // Toggle the LED every time the button is pressed
         if (pressEvent) {
             led = !led ;
             pressEvent = 0 ; // Clear the event variable
         }
         Thread::wait(100) ;
     }
-}
-
-int main() {
-    button.mode(PullUp);             // Ensure button i/p has pull up
-    button.fall(&buttonCallback) ;   // Attach function to falling edge
-
-    flashT.start(&flash) ; // Start the flashing thread running 
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Tue Jan 16 18:14:21 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#96d9a00d0a1d25095b330095fa81c40f7741777c
--- a/mbed-rtos.lib	Tue Jan 24 18:31:35 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- a/mbed.bld	Tue Jan 24 18:31:35 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5
\ No newline at end of file