Configure the joystick pins as interruptIn and print the directionthe joystick is pushed

Dependencies:   mbed

Committer:
t00203959
Date:
Wed May 22 11:52:08 2019 +0000
Revision:
0:2f505843d343
Lab 1 Digital Interrupts

Who changed what in which revision?

UserRevisionLine numberNew contents of line
t00203959 0:2f505843d343 1 #include "mbed.h"
t00203959 0:2f505843d343 2
t00203959 0:2f505843d343 3 Serial pc(USBTX,USBRX);
t00203959 0:2f505843d343 4 InterruptIn left(p13);
t00203959 0:2f505843d343 5 InterruptIn down(p12);
t00203959 0:2f505843d343 6 InterruptIn right(p16);
t00203959 0:2f505843d343 7 InterruptIn up(p15);
t00203959 0:2f505843d343 8 InterruptIn centre(p14);
t00203959 0:2f505843d343 9
t00203959 0:2f505843d343 10 void Down()
t00203959 0:2f505843d343 11 {
t00203959 0:2f505843d343 12 pc.printf("Down\n");
t00203959 0:2f505843d343 13 }
t00203959 0:2f505843d343 14 void Left()
t00203959 0:2f505843d343 15 {
t00203959 0:2f505843d343 16 pc.printf("Left\n");
t00203959 0:2f505843d343 17 }
t00203959 0:2f505843d343 18 void Centre()
t00203959 0:2f505843d343 19 {
t00203959 0:2f505843d343 20 pc.printf("Centre\n");
t00203959 0:2f505843d343 21 }
t00203959 0:2f505843d343 22 void Up()
t00203959 0:2f505843d343 23 {
t00203959 0:2f505843d343 24 pc.printf("Up\n");
t00203959 0:2f505843d343 25 }
t00203959 0:2f505843d343 26 void Right()
t00203959 0:2f505843d343 27 {
t00203959 0:2f505843d343 28 pc.printf("Right\n");
t00203959 0:2f505843d343 29 }
t00203959 0:2f505843d343 30
t00203959 0:2f505843d343 31 int main()
t00203959 0:2f505843d343 32 {
t00203959 0:2f505843d343 33 while(1) {
t00203959 0:2f505843d343 34 down.rise(&Down);
t00203959 0:2f505843d343 35 left.rise(&Left);
t00203959 0:2f505843d343 36 centre.rise(&Centre);
t00203959 0:2f505843d343 37 up.rise(&Up);
t00203959 0:2f505843d343 38 right.rise(&Right);
t00203959 0:2f505843d343 39 down.rise(&Down);
t00203959 0:2f505843d343 40 }
t00203959 0:2f505843d343 41
t00203959 0:2f505843d343 42
t00203959 0:2f505843d343 43 }