USBMouse

mbed OS 2 and mbed OS 5

This is the handbook for mbed OS 2. If you’re working with mbed OS 5, please see the new handbook and API References.

The USBMouse interface is used to emulate a mouse over the USB port. You can choose relative or absolute co-ordinates, and send clicks, button state and scroll wheel movements.

The USB connector should be attached to

  • p31 (D+), p32 (D-) and GND for the LPC1768 and the LPC11U24
  • The on-board USB connector of the FRDM-KL25Z

Hello World

Import program

00001 #include "mbed.h"
00002 #include "USBMouse.h"
00003 
00004 USBMouse mouse;
00005 
00006 int main() {
00007     int16_t x = 0;
00008     int16_t y = 0;
00009     int32_t radius = 10;
00010     int32_t angle = 0;
00011 
00012     while (1) {
00013         x = cos((double)angle*3.14/180.0)*radius;
00014         y = sin((double)angle*3.14/180.0)*radius;
00015         
00016         mouse.move(x, y);
00017         angle += 3;
00018         wait(0.001);
00019     }
00020 }

API

[Not found]

Details

You can choose either a relative mouse or an absolute mouse. By default, a USBMouse is a relative mouse. For instance, you can use an absolute mouse to draw a circle:

 #include "mbed.h"
 #include "USBMouse.h"

 USBMouse mouse(ABS_MOUSE);

 #include <math.h>

 int main(void)
 {
   uint16_t x_center = (X_MAX_ABS - X_MIN_ABS)/2;
   uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2;
   uint16_t x_screen = 0;
   uint16_t y_screen = 0;
   
   uint32_t x_origin = x_center;
   uint32_t y_origin = y_center;
   uint32_t radius = 5000;
   uint32_t angle = 0;

   while (1)
   {
       x_screen = x_origin + cos((double)angle*3.14/180.0)*radius;
       y_screen = y_origin + sin((double)angle*3.14/180.0)*radius;
       
       mouse.move(x_screen, y_screen);
       angle += 3;
       wait(0.01);
   }
 }