LAB#1: InterruptIn

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
hulmpants
Date:
Thu Aug 15 16:56:39 2019 +0000
Parent:
0:0e4db18afd77
Commit message:
Embedded_LAB1

Changed in this revision

Emb_LAB1.cpp Show annotated file Show diff for this revision Revisions of this file
Emb_LAB1_2.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Emb_LAB1.cpp	Thu Aug 15 16:56:39 2019 +0000
@@ -0,0 +1,46 @@
+// IT Tralee Mechatronics: Embedded Systems LAB#1
+
+
+#include "mbed.h"
+
+InterruptIn d(p12); // down
+InterruptIn l(p13); // left
+InterruptIn c(p14); // centre
+InterruptIn u(p15); // up
+InterruptIn r(p16); // right
+
+
+DigitalOut flash(LED1);
+
+void left() {
+   printf("Left \n \r"); // print
+}
+
+void right() {
+    printf("Right \n \r");
+}
+
+void up() {
+    printf("Up \n \r");
+}
+
+void down() {
+    printf("Down \n \r");
+}
+
+void centre() {
+    printf("Centre \n \r");
+}
+
+int main() {
+    l.rise(&left);  // address to interrupt rising edge
+    r.rise(&right);  
+    u.rise(&up);
+    d.rise(&down);   
+    c.rise(&centre);     
+
+    while(1) {           // LED flash = interrupt active
+        flash = !flash;
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Emb_LAB1_2.cpp	Thu Aug 15 16:56:39 2019 +0000
@@ -0,0 +1,53 @@
+// IT Tralee Mechatronics: Embedded Systems LAB#1
+// Revised code to include a simple software solution to mechanical bounce experienced by switch
+
+
+#include "mbed.h"
+
+InterruptIn d(p12); // down
+InterruptIn l(p13); // left
+InterruptIn c(p14); // centre
+InterruptIn u(p15); // up
+InterruptIn r(p16); // right
+
+
+DigitalOut flash(LED1);
+float debounce(0.5); // 0.5s delay: software sln for mechanical bounce 
+
+void left() {
+   printf("Left \n \r"); // print
+   wait(debounce);  
+}
+
+void right() {
+    printf("Right \n \r");
+    wait(debounce);    
+}
+
+void up() {
+    printf("Up \n \r");
+    wait(debounce);
+}
+
+void down() {
+    printf("Down \n \r");
+    wait(debounce);    
+}
+
+void centre() {
+    printf("Centre \n \r");
+    wait(debounce);
+}
+
+int main() {
+    l.rise(&left);  // attach the address of the (left in this line) functions to the interrupt rising edge. 0->1
+    r.rise(&right);  
+    u.rise(&up);
+    d.rise(&down);   
+    c.rise(&centre);     
+
+    while(1) {           // flash led1 until interrupt to show that program is stopping while interrupt is active. 
+        flash = !flash;
+        wait(0.2);
+    }
+}
--- a/main.cpp	Mon Oct 15 13:37:36 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#include "mbed.h"
-
-BusIn joy(p15,p12,p13,p16);
-DigitalIn fire(p14);
-
-BusOut leds(LED1,LED2,LED3,LED4);
-
-int main()
-{
-    while(1) {
-        if (fire) {
-            leds=0xf;
-        } else {
-            leds=joy;
-        }
-        wait(0.1);
-    }
-}