Use joystick to write position on to tera term using Interrupt

Dependencies:   mbed

Committer:
rudolf5020
Date:
Tue Aug 18 06:28:37 2020 +0000
Revision:
0:685104e87cb2
Question 1 part 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rudolf5020 0:685104e87cb2 1 #include "mbed.h" //
rudolf5020 0:685104e87cb2 2
rudolf5020 0:685104e87cb2 3 Serial pc(USBTX,USBRX); //serial communication to PC
rudolf5020 0:685104e87cb2 4
rudolf5020 0:685104e87cb2 5 InterruptIn down(p12); //declare Pin 12 joystick down
rudolf5020 0:685104e87cb2 6 InterruptIn left(p13); //declare Pin 13 joystick left
rudolf5020 0:685104e87cb2 7 InterruptIn center(p14); //declare Pin 14 joystick left
rudolf5020 0:685104e87cb2 8 InterruptIn up(p15); //declare Pin 15 joystick left
rudolf5020 0:685104e87cb2 9 InterruptIn right(p16); //declare Pin 16 joystick left
rudolf5020 0:685104e87cb2 10
rudolf5020 0:685104e87cb2 11
rudolf5020 0:685104e87cb2 12 void Down(){
rudolf5020 0:685104e87cb2 13 pc.printf("DOWN\r\n"); //print on tera Term position in next line
rudolf5020 0:685104e87cb2 14 }
rudolf5020 0:685104e87cb2 15
rudolf5020 0:685104e87cb2 16 void Left(){
rudolf5020 0:685104e87cb2 17 pc.printf("LEFT\r\n");
rudolf5020 0:685104e87cb2 18
rudolf5020 0:685104e87cb2 19 }
rudolf5020 0:685104e87cb2 20 void Center(){
rudolf5020 0:685104e87cb2 21 pc.printf("CENTER\r\n");
rudolf5020 0:685104e87cb2 22 }
rudolf5020 0:685104e87cb2 23
rudolf5020 0:685104e87cb2 24 void Up(){
rudolf5020 0:685104e87cb2 25 pc.printf("UP\r\n");
rudolf5020 0:685104e87cb2 26 }
rudolf5020 0:685104e87cb2 27 void Right(){
rudolf5020 0:685104e87cb2 28 pc.printf("RIGHT\r\n");
rudolf5020 0:685104e87cb2 29 }
rudolf5020 0:685104e87cb2 30
rudolf5020 0:685104e87cb2 31 int main(){
rudolf5020 0:685104e87cb2 32 while (1){
rudolf5020 0:685104e87cb2 33 down.rise(&Down); // switches on the rising edge
rudolf5020 0:685104e87cb2 34 left.rise(&Left); // switches on the rising edge
rudolf5020 0:685104e87cb2 35 center.rise(&Center); // switches on the rising edge
rudolf5020 0:685104e87cb2 36 up.rise(&Up); // switches on the rising edge
rudolf5020 0:685104e87cb2 37 right.rise(&Right); // switches on the rising edge
rudolf5020 0:685104e87cb2 38 down.rise(&Down); // switches on the rising edge
rudolf5020 0:685104e87cb2 39 }
rudolf5020 0:685104e87cb2 40 }