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:bb422b8b8285, committed 2020-08-08
- Comitter:
- liammchale
- Date:
- Sat Aug 08 09:36:15 2020 +0000
- Parent:
- 0:7de212f91ff4
- Commit message:
- saved with comments attached, previously not included
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Aug 08 09:04:49 2020 +0000
+++ b/main.cpp Sat Aug 08 09:36:15 2020 +0000
@@ -1,46 +1,52 @@
+//embedded systems lab question 1
+//Write a program using interrupts on digital pins 12-16 (Joystick on Application board).
+// Use printf to print to terminal the direction the jostick is moved.
+// pin defined for Joystick Inputs and LED outputs as per Appliciation board.
+//improve the performace of the program by using a debounce function
+
#include "mbed.h" //preprocessor demands
Serial pc(USBTX,USBRX);//serial communication to PC via the tx,rx
-InterruptIn down(p12);//global declaration
-InterruptIn left(p13);//global declaration
-InterruptIn center(p14);//global declaration
-InterruptIn up(p15);//global declaration
-InterruptIn right(p16);//global declaration
+InterruptIn down(p12);//down
+InterruptIn left(p13);//left
+InterruptIn center(p14);//center
+InterruptIn up(p15);//up
+InterruptIn right(p16);//right
-float debounce(0.5);
+float debounce(0.5);//new mechancial bounce on the switch contacts
void Down(){
- pc.printf("DOWN\r\n");
- wait (debounce);
+ pc.printf("DOWN\r\n");//print new line, return to start of new line
+ wait (debounce);//waits the value of half a second set in above float
}
void Left(){
- pc.printf("LEFT\r\n");
- wait (debounce);
+ pc.printf("LEFT\r\n");//print new line, return to start of new line
+ wait (debounce);//waits the value of half a second set in above float
}
void Center(){
- pc.printf("CENTER\r\n");
- wait (debounce);
+ pc.printf("CENTER\r\n");//print new line, return to start of new line
+ wait (debounce);//waits the value of half a second set in above float
}
void Up(){
- pc.printf("UP\r\n");
- wait (debounce);
+ pc.printf("UP\r\n");//print new line, return to start of new line
+ wait (debounce);//waits the value of half a second set in above float
}
void Right(){
- pc.printf("RIGHT\r\n");
- wait (debounce);
+ pc.printf("RIGHT\r\n");//print new line, return to start of new line
+ wait (debounce);//waits the value of half a second set in above float
}
-int main(){
+int main(){//main program
while (1){
wait(5);
- down.rise(&Down);
- left.rise(&Left);
- center.rise(&Center);
- up.rise(&Up);
- right.rise(&Right);
- down.rise(&Down);
+ down.rise(&Down);//interrupt the rising edge (0>1)
+ left.rise(&Left);//interrupt the rising edge (0>1)
+ center.rise(&Center);//interrupt the rising edge (0>1)
+ up.rise(&Up);//interrupt the rising edge (0>1)
+ right.rise(&Right);//interrupt the rising edge (0>1)
+ down.rise(&Down);//interrupt the rising edge (0>1)
}
}