Ported a code that FRDM-KL46Z act as a USB mouse originally developed by jksoft, to FRDM-K22F. SW2 and SW3 act as left and right buttons respectively because K22F lacks a touch sensor, in contrast to KL46Z.

Dependencies:   FXOS8700Q USBDevice mbed

jksoftさんのUSBマウス(FRDM-KL46Z用)をFRDM-K22Fにポーティング。 KL46Zとは異なり、K22Fにはタッチセンサがありません。このため、SW2を左ボタン、SW3を右ボタンとしています。

Ported USB mouse for FRDM-KL46Z originally developed by jksoft to FRDM-K22F. SW2 and SW3 act as left and right buttons respectively because K22F lacks a touch sensor, in contrast to KL46Z.

Committer:
sknn
Date:
Sat Mar 21 13:52:35 2015 +0000
Revision:
1:3c6efa018b57
Parent:
0:2a59676aa462
Child:
2:0053ee456979
Translated Japanese comments into English

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sknn 0:2a59676aa462 1 #include "mbed.h"
sknn 0:2a59676aa462 2 #include "USBMouseKeyboard.h"
sknn 0:2a59676aa462 3 #include "FXOS8700Q.h"
sknn 0:2a59676aa462 4
sknn 1:3c6efa018b57 5 USBMouseKeyboard key_mouse; // Use USBMouseKeyboard which emulates USB mouse & keyboard
sknn 1:3c6efa018b57 6 FXOS8700Q_acc acc( PTB3, PTB2, FXOS8700CQ_SLAVE_ADDR2); // Use accelerometer
sknn 0:2a59676aa462 7 MotionSensorDataUnits acc_data;
sknn 0:2a59676aa462 8 DigitalIn sw2(SW2);
sknn 0:2a59676aa462 9 DigitalIn sw3(SW3);
sknn 0:2a59676aa462 10
sknn 0:2a59676aa462 11 int main(void) {
sknn 0:2a59676aa462 12
sknn 0:2a59676aa462 13 acc.enable();
sknn 0:2a59676aa462 14
sknn 0:2a59676aa462 15 while (1) {
sknn 0:2a59676aa462 16 acc.getAxis(acc_data);
sknn 1:3c6efa018b57 17 float x = acc_data.x; // Substitute x for x-axis value of accelerometer
sknn 1:3c6efa018b57 18 float y = acc_data.y; // Substitute y for y-axis value of accelerometer
sknn 0:2a59676aa462 19
sknn 0:2a59676aa462 20 if( x > 0.3f ) {
sknn 1:3c6efa018b57 21 // Board is listing to the right
sknn 1:3c6efa018b57 22 key_mouse.move(10, 0); // Move the mouse cursor +10 in x-axis direction
sknn 0:2a59676aa462 23 } else if( x < -0.3 ) {
sknn 1:3c6efa018b57 24 // Board is listing to the left
sknn 1:3c6efa018b57 25 key_mouse.move(-10, 0); // Move the mouse cursor -10 in x-axis direction
sknn 0:2a59676aa462 26 }
sknn 0:2a59676aa462 27
sknn 0:2a59676aa462 28 if( y > 0.3f ){
sknn 1:3c6efa018b57 29 // Board is listing to the front
sknn 1:3c6efa018b57 30 key_mouse.move(0, -10); // Move the mouse cursor +10 in y-axis direction
sknn 0:2a59676aa462 31 } else if( y < -0.3 ) {
sknn 1:3c6efa018b57 32 // Board is listing to the back
sknn 1:3c6efa018b57 33 key_mouse.move(0, 10); // Move the mouse cursor -10 in y-axis direction
sknn 0:2a59676aa462 34 }
sknn 0:2a59676aa462 35
sknn 0:2a59676aa462 36 if( sw2 == 1 ) {
sknn 1:3c6efa018b57 37 // SW2 is not pressed
sknn 1:3c6efa018b57 38 key_mouse.release(MOUSE_LEFT); // Release the left button
sknn 0:2a59676aa462 39 } else {
sknn 1:3c6efa018b57 40 // SW2 is pressed
sknn 1:3c6efa018b57 41 key_mouse.press(MOUSE_LEFT); // Press the left button
sknn 0:2a59676aa462 42 }
sknn 0:2a59676aa462 43
sknn 0:2a59676aa462 44 if( sw3 == 1 ) {
sknn 1:3c6efa018b57 45 // SW3 is not pressed
sknn 1:3c6efa018b57 46 key_mouse.release(MOUSE_RIGHT); // Release the right button
sknn 0:2a59676aa462 47 } else {
sknn 1:3c6efa018b57 48 // SW3 is pressed
sknn 1:3c6efa018b57 49 key_mouse.press(MOUSE_RIGHT); // Press the right button
sknn 0:2a59676aa462 50 }
sknn 0:2a59676aa462 51 wait(0.1);
sknn 0:2a59676aa462 52 }
sknn 0:2a59676aa462 53 }