Liam McHale / Mbed 2 deprecated EmbedQ1p2

Dependencies:   mbed

main.cpp

Committer:
liammchale
Date:
2020-08-08
Revision:
1:bb422b8b8285
Parent:
0:7de212f91ff4

File content as of revision 1:bb422b8b8285:

//embedded systems lab question 1
//Write a program using interrupts on digital pins 12-16 (Joystick on Application board).
// Use printf to print to terminal the direction the jostick is moved.
// pin defined for Joystick Inputs and LED outputs as per Appliciation board.
//improve the performace of the program by using a debounce function

#include "mbed.h" //preprocessor demands

Serial pc(USBTX,USBRX);//serial communication to PC via the tx,rx

InterruptIn down(p12);//down
InterruptIn left(p13);//left
InterruptIn center(p14);//center
InterruptIn up(p15);//up
InterruptIn right(p16);//right

float debounce(0.5);//new mechancial bounce on the switch contacts


void Down(){
    pc.printf("DOWN\r\n");//print new line, return to start of new line
    wait (debounce);//waits the value of half a second set in above float
    }
void Left(){
    pc.printf("LEFT\r\n");//print new line, return to start of new line
    wait (debounce);//waits the value of half a second set in above float
    }
void Center(){
    pc.printf("CENTER\r\n");//print new line, return to start of new line
    wait (debounce);//waits the value of half a second set in above float
    }
void Up(){
    pc.printf("UP\r\n");//print new line, return to start of new line
    wait (debounce);//waits the value of half a second set in above float
    }
void Right(){
    pc.printf("RIGHT\r\n");//print new line, return to start of new line
    wait (debounce);//waits the value of half a second set in above float
    }
    
int main(){//main program
    while (1){
        wait(5);
        down.rise(&Down);//interrupt the rising edge (0>1)
        left.rise(&Left);//interrupt the rising edge (0>1)
        center.rise(&Center);//interrupt the rising edge (0>1)
        up.rise(&Up);//interrupt the rising edge (0>1)
        right.rise(&Right);//interrupt the rising edge (0>1)
        down.rise(&Down);//interrupt the rising edge (0>1)
        }
}