Example of usb mouse on smt32 platform using a analog 2-axis joystick

Dependencies:   USBDEVICE mbed

Committer:
julgonmej
Date:
Sat Apr 29 19:23:34 2017 +0000
Revision:
6:989396ea046f
Parent:
5:b3c465e3e54e
Child:
7:bb9d609a8493
Joystick

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jamike 0:6410755cb90c 1 #include "mbed.h"
jamike 0:6410755cb90c 2
jamike 0:6410755cb90c 3 #include <math.h>
jamike 0:6410755cb90c 4
jamike 0:6410755cb90c 5 #include "USBMouse.h"
jamike 0:6410755cb90c 6
jamike 0:6410755cb90c 7 USBMouse mouse(ABS_MOUSE);
julgonmej 5:b3c465e3e54e 8 DigitalOut myled(LED1);
jamike 0:6410755cb90c 9
julgonmej 6:989396ea046f 10 BusIn joy(PA_13, PA_14);
julgonmej 6:989396ea046f 11 DigitalIn click(PB_7);
julgonmej 6:989396ea046f 12
julgonmej 6:989396ea046f 13 Serial mipc(USBTX, USBRX);
julgonmej 6:989396ea046f 14
jamike 0:6410755cb90c 15 int main(void) {
julgonmej 6:989396ea046f 16 mipc.printf("HOLA");
jamike 0:6410755cb90c 17 int x_center = (X_MAX_ABS - X_MIN_ABS)/2;
jamike 0:6410755cb90c 18 int y_center = (Y_MAX_ABS - Y_MIN_ABS)/2;
jamike 0:6410755cb90c 19 int16_t x_screen = 0;
jamike 0:6410755cb90c 20 int16_t y_screen = 0;
julgonmej 5:b3c465e3e54e 21 myled = 0;
jamike 0:6410755cb90c 22
jamike 0:6410755cb90c 23 int32_t x_origin = x_center;
jamike 0:6410755cb90c 24 int32_t y_origin = y_center;
jamike 0:6410755cb90c 25 int32_t radius = 5000;
jamike 0:6410755cb90c 26 int32_t angle = 0;
jamike 0:6410755cb90c 27
jamike 0:6410755cb90c 28 while (1) {
julgonmej 6:989396ea046f 29 mipc.printf("PALANCA %d, BOTON %d\r", joy.read(), click);
julgonmej 5:b3c465e3e54e 30 myled = !myled;
jamike 0:6410755cb90c 31 x_screen = x_origin + cos((double)angle*3.14/180.0)*radius;
jamike 0:6410755cb90c 32 y_screen = y_origin + sin((double)angle*3.14/180.0)*radius;
jamike 0:6410755cb90c 33 printf("cos: %f, sin: %f\r\n", cos((double)angle*3.14/180.0)*radius, sin((double)angle)*radius);
jamike 0:6410755cb90c 34
jamike 0:6410755cb90c 35 mouse.move(x_screen, y_screen);
jamike 0:6410755cb90c 36 angle += 3;
jamike 0:6410755cb90c 37 wait(0.01);
jamike 0:6410755cb90c 38 }
jamike 0:6410755cb90c 39 }