FRDM-K64 USB Mouse basic example using mbed

Document created by Pedro Augusto Panecatl Salas Employee on Jun 27, 2014Last modified by ebiz_ws_prod on Dec 13, 2017
Version 5Show Document
  • View in full screen mode

Here you will find both the code and project files for the USB Mouse project. In this project the USB module is configured as a device, the X and Y coordinates to move the cursor are obtained from the accelerometer measurements. Once the code is loaded it is necessary to disconnect the USB cable from the J26 USB connector and plug it to the K64 USB connector. Once the device enumerates you can use it as an air mouse.


The left and right click buttons have not been enabled.


To compile the project you must import the following libraries:

  • USBMouse.h
  • FXOS8700Q.h




#include "mbed.h"

#include "USBMouse.h"

#include "FXOS8700Q.h"


//I2C lines for FXOS8700Q accelerometer/magnetometer

FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);


USBMouse mouse;


int main()



    float faX, faY, faZ;

    int16_t x = 0;

    int16_t y = 0;


    while (1)





        x = 10*faX;

        y = 10*faY;


        mouse.move(x, y);




Original Attachment has been moved to:

Original Attachment has been moved to: