
embedded systems, Lab, Question 1 part A
main.cpp@0:b3bbfb3941ed, 2020-08-08 (annotated)
- Committer:
- liammchale
- Date:
- Sat Aug 08 09:23:25 2020 +0000
- Revision:
- 0:b3bbfb3941ed
finished with comments now included
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
liammchale | 0:b3bbfb3941ed | 1 | //embedded systems lab question 1 |
liammchale | 0:b3bbfb3941ed | 2 | //Write a program using interrupts on digital pins 12-16 (Joystick on Application board). |
liammchale | 0:b3bbfb3941ed | 3 | // Use printf to print to terminal the direction the jostick is moved. |
liammchale | 0:b3bbfb3941ed | 4 | // pin defined for Joystick Inputs and LED outputs as per Appliciation board. |
liammchale | 0:b3bbfb3941ed | 5 | |
liammchale | 0:b3bbfb3941ed | 6 | #include "mbed.h" //preprocessor command |
liammchale | 0:b3bbfb3941ed | 7 | |
liammchale | 0:b3bbfb3941ed | 8 | Serial pc(USBTX,USBRX);//serial communication to PC via the tx,rx |
liammchale | 0:b3bbfb3941ed | 9 | |
liammchale | 0:b3bbfb3941ed | 10 | InterruptIn down(p12);//down |
liammchale | 0:b3bbfb3941ed | 11 | InterruptIn left(p13);//left |
liammchale | 0:b3bbfb3941ed | 12 | InterruptIn center(p14);//center |
liammchale | 0:b3bbfb3941ed | 13 | InterruptIn up(p15);//up |
liammchale | 0:b3bbfb3941ed | 14 | InterruptIn right(p16);//right |
liammchale | 0:b3bbfb3941ed | 15 | |
liammchale | 0:b3bbfb3941ed | 16 | |
liammchale | 0:b3bbfb3941ed | 17 | void Down(){ |
liammchale | 0:b3bbfb3941ed | 18 | pc.printf("DOWN\r\n");//print, return to start position of new line |
liammchale | 0:b3bbfb3941ed | 19 | } |
liammchale | 0:b3bbfb3941ed | 20 | void Left(){ |
liammchale | 0:b3bbfb3941ed | 21 | pc.printf("LEFT\r\n");//print, return to start position of new line |
liammchale | 0:b3bbfb3941ed | 22 | } |
liammchale | 0:b3bbfb3941ed | 23 | void Center(){ |
liammchale | 0:b3bbfb3941ed | 24 | pc.printf("CENTER\r\n");//print, return to start position of new line |
liammchale | 0:b3bbfb3941ed | 25 | } |
liammchale | 0:b3bbfb3941ed | 26 | void Up(){ |
liammchale | 0:b3bbfb3941ed | 27 | pc.printf("UP\r\n");//print, return to start position of new line |
liammchale | 0:b3bbfb3941ed | 28 | } |
liammchale | 0:b3bbfb3941ed | 29 | void Right(){ |
liammchale | 0:b3bbfb3941ed | 30 | pc.printf("RIGHT\r\n");//print, return to start position of new line |
liammchale | 0:b3bbfb3941ed | 31 | } |
liammchale | 0:b3bbfb3941ed | 32 | |
liammchale | 0:b3bbfb3941ed | 33 | int main(){//main program command |
liammchale | 0:b3bbfb3941ed | 34 | while (1){ |
liammchale | 0:b3bbfb3941ed | 35 | down.rise(&Down);//interrupt on the rising edge |
liammchale | 0:b3bbfb3941ed | 36 | left.rise(&Left);//interupt on the rising edge |
liammchale | 0:b3bbfb3941ed | 37 | center.rise(&Center);//interrupt on the rising edge |
liammchale | 0:b3bbfb3941ed | 38 | up.rise(&Up);//interrupt on the rising edge |
liammchale | 0:b3bbfb3941ed | 39 | right.rise(&Right);//interrupt on the rising edge |
liammchale | 0:b3bbfb3941ed | 40 | down.rise(&Down);//interrupt on the rising edge |
liammchale | 0:b3bbfb3941ed | 41 | } |
liammchale | 0:b3bbfb3941ed | 42 | } |
liammchale | 0:b3bbfb3941ed | 43 | |
liammchale | 0:b3bbfb3941ed | 44 |