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.
Revision 1:3c6efa018b57, committed 2015-03-21
- Comitter:
- sknn
- Date:
- Sat Mar 21 13:52:35 2015 +0000
- Parent:
- 0:2a59676aa462
- Child:
- 2:0053ee456979
- Commit message:
- Translated Japanese comments into English
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Mar 21 10:41:49 2015 +0000 +++ b/main.cpp Sat Mar 21 13:52:35 2015 +0000 @@ -2,8 +2,8 @@ #include "USBMouseKeyboard.h" #include "FXOS8700Q.h" -USBMouseKeyboard key_mouse; // USBキーボードマウスライブラリを使う -FXOS8700Q_acc acc( PTB3, PTB2, FXOS8700CQ_SLAVE_ADDR2); // 加速度センサライブラリを使う +USBMouseKeyboard key_mouse; // Use USBMouseKeyboard which emulates USB mouse & keyboard +FXOS8700Q_acc acc( PTB3, PTB2, FXOS8700CQ_SLAVE_ADDR2); // Use accelerometer MotionSensorDataUnits acc_data; DigitalIn sw2(SW2); DigitalIn sw3(SW3); @@ -14,39 +14,39 @@ while (1) { acc.getAxis(acc_data); - float x = acc_data.x; // 加速度センサX軸の値を変数xに代入 - float y = acc_data.y; // 加速度センサy軸の値を変数yに代入 + float x = acc_data.x; // Substitute x for x-axis value of accelerometer + float y = acc_data.y; // Substitute y for y-axis value of accelerometer if( x > 0.3f ) { - // ボードが右に傾いてる - key_mouse.move(10, 0); // マウスカーソルをX方向に10動かす + // Board is listing to the right + key_mouse.move(10, 0); // Move the mouse cursor +10 in x-axis direction } else if( x < -0.3 ) { - // ボードが左に傾いてる - key_mouse.move(-10, 0); // マウスカーソルをX方向に-10動かす + // Board is listing to the left + key_mouse.move(-10, 0); // Move the mouse cursor -10 in x-axis direction } if( y > 0.3f ){ - // ボードが前に傾いてる - key_mouse.move(0, -10); // マウスカーソルをY方向に-10動かす + // Board is listing to the front + key_mouse.move(0, -10); // Move the mouse cursor +10 in y-axis direction } else if( y < -0.3 ) { - // ボードが後ろに傾いてる - key_mouse.move(0, 10); // マウスカーソルをY方向に10動かす + // Board is listing to the back + key_mouse.move(0, 10); // Move the mouse cursor -10 in y-axis direction } if( sw2 == 1 ) { - // SW2が押されていない状態 - key_mouse.release(MOUSE_LEFT); // マウス左クリックを解放した状態にする + // SW2 is not pressed + key_mouse.release(MOUSE_LEFT); // Release the left button } else { - // SW2が押されている状態 - key_mouse.press(MOUSE_LEFT); // マウス左クリックをクリックした状態にする + // SW2 is pressed + key_mouse.press(MOUSE_LEFT); // Press the left button } if( sw3 == 1 ) { - // SW3が押されていない状態 - key_mouse.release(MOUSE_RIGHT); // マウス右クリックを解放した状態にする + // SW3 is not pressed + key_mouse.release(MOUSE_RIGHT); // Release the right button } else { - // SW3が押されている状態 - key_mouse.press(MOUSE_RIGHT); // マウス右クリックをクリックした状態にする + // SW3 is pressed + key_mouse.press(MOUSE_RIGHT); // Press the right button } wait(0.1); }