Lab Question 1 Digital Interrupts

Dependencies:   mbed

main.cpp

Committer:
johnc89
Date:
2021-04-17
Revision:
1:80741e2594b1
Parent:
0:3899a7a0bffb

File content as of revision 1:80741e2594b1:

#include "mbed.h"
// Lab1 Digital Interrupts
//John Curran T00214119
// Queston 1 (b)Do you see multiple lines printed even when the joystick is toggled once? Why? Why Not!?
// Question 1 (b) Answer : without a 'wait' time i do , however when i introduce a wait time i dont,
// and it will just print what direction joystick is pressed on a seperate line
// Question 1 (c) What software or hardware solution can be applied to get a decent output?
// Question 1 (c) Answer : 'wait' & 'timers' can be used, a capacitor can be used across the switch, 'debounce' can be used

// This programs prints on Tera Term what direction the joystick is pressed
Serial pc(USBTX, USBRX); // serial communications tx, rx
InterruptIn UP (p15); // Press Up on Joystick
InterruptIn DOWN (p12); // Press Down on Joystick
InterruptIn LEFT (p13); // Press Up on Joystick
InterruptIn RIGHT (p16); // Press Down on Joystick
InterruptIn CENTRE (p14); // Press Down on Joystick

int main ()
{

    {


        pc.printf ("'LAB 1 DIGITAL INTERRUPTS JOHN CURRAN T00214119'\n\r");//prints text on screen


        while (1) { //infinite loop

            if(UP == 1) {
                pc.printf ("'UP is Pressed'\n\r");//print UP on screen
            }

            if(DOWN == 1) {
                pc.printf ("'DOWN is Pressed'\n\r");//print DOWN on screen
            }
            wait (0.5);
            if(LEFT == 1) {
                pc.printf ("'LEFT is Pressed'\n\r");//print LEFT on screen
            }

            if(RIGHT == 1) {
                pc.printf ("'RIGHT is Pressed'\n\r");//print RIGHT on screen
            }

            if(CENTRE == 1) {
                pc.printf ("'CENTRE is Pressed'\n\r");//print CENTRE on screen
            }


        }
    }
}