John Curran
/
lab1_Digital_Interrupts_JohnCurran_T00214119
Lab Question 1 Digital Interrupts
main.cpp@1:80741e2594b1, 2021-04-17 (annotated)
- Committer:
- johnc89
- Date:
- Sat Apr 17 10:17:41 2021 +0000
- Revision:
- 1:80741e2594b1
- Parent:
- 0:3899a7a0bffb
Improved Code 1(d) I included a 'wait' time to improve the layout of screen on Tera -Term
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnc89 | 0:3899a7a0bffb | 1 | #include "mbed.h" |
johnc89 | 0:3899a7a0bffb | 2 | // Lab1 Digital Interrupts |
johnc89 | 0:3899a7a0bffb | 3 | //John Curran T00214119 |
johnc89 | 1:80741e2594b1 | 4 | // Queston 1 (b)Do you see multiple lines printed even when the joystick is toggled once? Why? Why Not!? |
johnc89 | 1:80741e2594b1 | 5 | // Question 1 (b) Answer : without a 'wait' time i do , however when i introduce a wait time i dont, |
johnc89 | 1:80741e2594b1 | 6 | // and it will just print what direction joystick is pressed on a seperate line |
johnc89 | 1:80741e2594b1 | 7 | // Question 1 (c) What software or hardware solution can be applied to get a decent output? |
johnc89 | 1:80741e2594b1 | 8 | // Question 1 (c) Answer : 'wait' & 'timers' can be used, a capacitor can be used across the switch, 'debounce' can be used |
johnc89 | 1:80741e2594b1 | 9 | |
johnc89 | 1:80741e2594b1 | 10 | // This programs prints on Tera Term what direction the joystick is pressed |
johnc89 | 1:80741e2594b1 | 11 | Serial pc(USBTX, USBRX); // serial communications tx, rx |
johnc89 | 0:3899a7a0bffb | 12 | InterruptIn UP (p15); // Press Up on Joystick |
johnc89 | 0:3899a7a0bffb | 13 | InterruptIn DOWN (p12); // Press Down on Joystick |
johnc89 | 0:3899a7a0bffb | 14 | InterruptIn LEFT (p13); // Press Up on Joystick |
johnc89 | 0:3899a7a0bffb | 15 | InterruptIn RIGHT (p16); // Press Down on Joystick |
johnc89 | 0:3899a7a0bffb | 16 | InterruptIn CENTRE (p14); // Press Down on Joystick |
johnc89 | 0:3899a7a0bffb | 17 | |
johnc89 | 0:3899a7a0bffb | 18 | int main () |
johnc89 | 0:3899a7a0bffb | 19 | { |
johnc89 | 0:3899a7a0bffb | 20 | |
johnc89 | 0:3899a7a0bffb | 21 | { |
johnc89 | 0:3899a7a0bffb | 22 | |
johnc89 | 0:3899a7a0bffb | 23 | |
johnc89 | 0:3899a7a0bffb | 24 | pc.printf ("'LAB 1 DIGITAL INTERRUPTS JOHN CURRAN T00214119'\n\r");//prints text on screen |
johnc89 | 0:3899a7a0bffb | 25 | |
johnc89 | 0:3899a7a0bffb | 26 | |
johnc89 | 0:3899a7a0bffb | 27 | while (1) { //infinite loop |
johnc89 | 0:3899a7a0bffb | 28 | |
johnc89 | 0:3899a7a0bffb | 29 | if(UP == 1) { |
johnc89 | 0:3899a7a0bffb | 30 | pc.printf ("'UP is Pressed'\n\r");//print UP on screen |
johnc89 | 0:3899a7a0bffb | 31 | } |
johnc89 | 1:80741e2594b1 | 32 | |
johnc89 | 0:3899a7a0bffb | 33 | if(DOWN == 1) { |
johnc89 | 0:3899a7a0bffb | 34 | pc.printf ("'DOWN is Pressed'\n\r");//print DOWN on screen |
johnc89 | 0:3899a7a0bffb | 35 | } |
johnc89 | 0:3899a7a0bffb | 36 | wait (0.5); |
johnc89 | 0:3899a7a0bffb | 37 | if(LEFT == 1) { |
johnc89 | 0:3899a7a0bffb | 38 | pc.printf ("'LEFT is Pressed'\n\r");//print LEFT on screen |
johnc89 | 0:3899a7a0bffb | 39 | } |
johnc89 | 1:80741e2594b1 | 40 | |
johnc89 | 0:3899a7a0bffb | 41 | if(RIGHT == 1) { |
johnc89 | 0:3899a7a0bffb | 42 | pc.printf ("'RIGHT is Pressed'\n\r");//print RIGHT on screen |
johnc89 | 0:3899a7a0bffb | 43 | } |
johnc89 | 1:80741e2594b1 | 44 | |
johnc89 | 0:3899a7a0bffb | 45 | if(CENTRE == 1) { |
johnc89 | 0:3899a7a0bffb | 46 | pc.printf ("'CENTRE is Pressed'\n\r");//print CENTRE on screen |
johnc89 | 0:3899a7a0bffb | 47 | } |
johnc89 | 1:80741e2594b1 | 48 | |
johnc89 | 0:3899a7a0bffb | 49 | |
johnc89 | 0:3899a7a0bffb | 50 | } |
johnc89 | 0:3899a7a0bffb | 51 | } |
johnc89 | 1:80741e2594b1 | 52 | } |