Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:cd0e7975714c, committed 2019-08-15
- Comitter:
- hulmpants
- Date:
- Thu Aug 15 16:56:39 2019 +0000
- Parent:
- 0:0e4db18afd77
- Commit message:
- Embedded_LAB1
Changed in this revision
--- /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(¢re);
+
+ 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(¢re);
+
+ 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);
- }
-}