Joy to the world

Dependencies:   Joystick mbed

Committer:
jvfausto
Date:
Fri Jul 13 22:24:30 2018 +0000
Revision:
0:34022ad4a23d
Joy to the world

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jvfausto 0:34022ad4a23d 1 #include "mbed.h"
jvfausto 0:34022ad4a23d 2 #include "Joystick.h"
jvfausto 0:34022ad4a23d 3
jvfausto 0:34022ad4a23d 4 // Xaxis,Yaxis,Button
jvfausto 0:34022ad4a23d 5 Joystick joystick(PTB2, PTB3, PTB11);
jvfausto 0:34022ad4a23d 6 DigitalOut r_led(LED_RED);
jvfausto 0:34022ad4a23d 7 Serial pc(USBTX, USBRX);
jvfausto 0:34022ad4a23d 8
jvfausto 0:34022ad4a23d 9 int main()
jvfausto 0:34022ad4a23d 10 {
jvfausto 0:34022ad4a23d 11 //First initalise joystick
jvfausto 0:34022ad4a23d 12 joystick.init();
jvfausto 0:34022ad4a23d 13
jvfausto 0:34022ad4a23d 14 while (true) {
jvfausto 0:34022ad4a23d 15
jvfausto 0:34022ad4a23d 16 Vector2D coord = joystick.get_coord();
jvfausto 0:34022ad4a23d 17 pc.printf("Coord = x %3f\ty %3f\r\n",(coord.x+1)/2,(coord.y+1)/2);
jvfausto 0:34022ad4a23d 18 //If the button flag is pressed switch the led
jvfausto 0:34022ad4a23d 19 /* if (joystick.button_pressed()) {
jvfausto 0:34022ad4a23d 20 pc.printf("button is pressed\t");
jvfausto 0:34022ad4a23d 21 r_led = !r_led;
jvfausto 0:34022ad4a23d 22 }*/
jvfausto 0:34022ad4a23d 23 }
jvfausto 0:34022ad4a23d 24 }