Ger Roche
/
mbed_Lab1_Joystick2
Lab1.2
main.cpp@1:809827e05de5, 2019-05-23 (annotated)
- Committer:
- t00203907
- Date:
- Thu May 23 20:50:15 2019 +0000
- Revision:
- 1:809827e05de5
- Parent:
- 0:bf301f967bc5
- Child:
- 2:426f7c929554
Update of Joystick Program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
t00203907 | 0:bf301f967bc5 | 1 | #include "mbed.h" |
t00203907 | 0:bf301f967bc5 | 2 | |
t00203907 | 1:809827e05de5 | 3 | Serial pc(USBTX,USBRX);// sets up serial connection to PC |
t00203907 | 1:809827e05de5 | 4 | InterruptIn DN(p12);// declares p12 as an intrrupt In called DN |
t00203907 | 1:809827e05de5 | 5 | InterruptIn LH(p13);// declares p13 as an intrrupt In called LH |
t00203907 | 1:809827e05de5 | 6 | InterruptIn CN(p14);// declares p14 as an intrrupt In called CN |
t00203907 | 1:809827e05de5 | 7 | InterruptIn UP(p15);// declares p15 as an intrrupt In called UP |
t00203907 | 1:809827e05de5 | 8 | InterruptIn RH(p16);// declares p16 as an intrrupt In called RH |
t00203907 | 0:bf301f967bc5 | 9 | |
t00203907 | 0:bf301f967bc5 | 10 | void print1() |
t00203907 | 0:bf301f967bc5 | 11 | { |
t00203907 | 1:809827e05de5 | 12 | printf("Down Pressed\r\n");// prints to the PC when print1 is activated |
t00203907 | 1:809827e05de5 | 13 | wait(0.75);// waits 0.75 seconds |
t00203907 | 0:bf301f967bc5 | 14 | } |
t00203907 | 0:bf301f967bc5 | 15 | void print2() |
t00203907 | 0:bf301f967bc5 | 16 | { |
t00203907 | 1:809827e05de5 | 17 | printf("Left Pressed\r\n");// prints to the PC when print2 is activated |
t00203907 | 1:809827e05de5 | 18 | wait(0.75);// waits 0.75 seconds |
t00203907 | 0:bf301f967bc5 | 19 | } |
t00203907 | 0:bf301f967bc5 | 20 | void print3() |
t00203907 | 0:bf301f967bc5 | 21 | { |
t00203907 | 1:809827e05de5 | 22 | printf("Centre Pressed\r\n");// prints to the PC when print3 is activated |
t00203907 | 1:809827e05de5 | 23 | wait(0.75);// waits 0.75 seconds |
t00203907 | 0:bf301f967bc5 | 24 | } |
t00203907 | 0:bf301f967bc5 | 25 | void print4() |
t00203907 | 0:bf301f967bc5 | 26 | { |
t00203907 | 1:809827e05de5 | 27 | printf("Up Pressed\r\n");// prints to the PC when print4 is activated |
t00203907 | 1:809827e05de5 | 28 | wait(0.75);// waits 0.75 seconds |
t00203907 | 0:bf301f967bc5 | 29 | } |
t00203907 | 0:bf301f967bc5 | 30 | void print5() |
t00203907 | 0:bf301f967bc5 | 31 | { |
t00203907 | 1:809827e05de5 | 32 | printf("Right Pressed\r\n");// prints to the PC when print5 is activated |
t00203907 | 1:809827e05de5 | 33 | wait(0.75);// waits 0.75 seconds |
t00203907 | 0:bf301f967bc5 | 34 | } |
t00203907 | 0:bf301f967bc5 | 35 | |
t00203907 | 0:bf301f967bc5 | 36 | int main() |
t00203907 | 0:bf301f967bc5 | 37 | { |
t00203907 | 1:809827e05de5 | 38 | printf("Hello\r\n");// prints "Hello" at the top of the screen |
t00203907 | 1:809827e05de5 | 39 | DN.rise(&print1);// prints first print statment when value goes from 0V to 3.3V and p12 is hit |
t00203907 | 1:809827e05de5 | 40 | LH.rise(&print2);// prints second print statment when value goes from 0V to 3.3V and p13 is hit |
t00203907 | 1:809827e05de5 | 41 | CN.rise(&print3);// prints third print statment when value goes from 0V to 3.3V and p14 is hit |
t00203907 | 1:809827e05de5 | 42 | UP.rise(&print4);// prints fourth print statment when value goes from 0V to 3.3V and p15 is hit |
t00203907 | 1:809827e05de5 | 43 | RH.rise(&print5);// prints fifth print statment when value goes from 0V to 3.3V and p16 is hit |
t00203907 | 1:809827e05de5 | 44 | wait(0.5);// waits 0.5 seconds |
t00203907 | 0:bf301f967bc5 | 45 | while(1) { |
t00203907 | 0:bf301f967bc5 | 46 | |
t00203907 | 0:bf301f967bc5 | 47 | } |
t00203907 | 0:bf301f967bc5 | 48 | } |