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