Example of usbmouse on smt32 platform

Dependencies:   USBDEVICE mbed

Committer:
arostm
Date:
Wed Jun 07 14:25:14 2017 +0000
Revision:
6:b6e9ca6a0bf6
Parent:
5:d6fefea561f8
Adding new mbed library

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 5:d6fefea561f8 7 InterruptIn button(USER_BUTTON);
jamike 5:d6fefea561f8 8
jamike 0:6410755cb90c 9 USBMouse mouse(ABS_MOUSE);
jamike 5:d6fefea561f8 10 volatile bool send=true;
jamike 5:d6fefea561f8 11 void handlerbutton()
jamike 5:d6fefea561f8 12 {
jamike 5:d6fefea561f8 13 send=!send;
jamike 5:d6fefea561f8 14 }
jamike 0:6410755cb90c 15 int main(void) {
jamike 0:6410755cb90c 16 int x_center = (X_MAX_ABS - X_MIN_ABS)/2;
jamike 0:6410755cb90c 17 int y_center = (Y_MAX_ABS - Y_MIN_ABS)/2;
jamike 0:6410755cb90c 18 int16_t x_screen = 0;
jamike 0:6410755cb90c 19 int16_t y_screen = 0;
jamike 0:6410755cb90c 20
jamike 0:6410755cb90c 21 int32_t x_origin = x_center;
jamike 0:6410755cb90c 22 int32_t y_origin = y_center;
jamike 0:6410755cb90c 23 int32_t radius = 5000;
jamike 0:6410755cb90c 24 int32_t angle = 0;
jamike 5:d6fefea561f8 25 button.rise(&handlerbutton);
jamike 0:6410755cb90c 26
jamike 0:6410755cb90c 27 while (1) {
jamike 0:6410755cb90c 28 x_screen = x_origin + cos((double)angle*3.14/180.0)*radius;
jamike 0:6410755cb90c 29 y_screen = y_origin + sin((double)angle*3.14/180.0)*radius;
jamike 0:6410755cb90c 30 printf("cos: %f, sin: %f\r\n", cos((double)angle*3.14/180.0)*radius, sin((double)angle)*radius);
jamike 0:6410755cb90c 31
jamike 5:d6fefea561f8 32 if (send) mouse.move(x_screen, y_screen);
jamike 0:6410755cb90c 33 angle += 3;
jamike 0:6410755cb90c 34 wait(0.01);
jamike 0:6410755cb90c 35 }
jamike 0:6410755cb90c 36 }