source: rtos_arduino/trunk/arduino_lib/libraries/USBHost/examples/MouseController/MouseController.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.9 KB
Line 
1/*
2 Mouse Controller Example
3
4 Shows the output of a USB Mouse connected to
5 the Native USB port on an Arduino Due Board.
6
7 created 8 Oct 2012
8 by Cristian Maglie
9
10 http://arduino.cc/en/Tutorial/MouseController
11
12 This sample code is part of the public domain.
13 */
14
15// Require mouse control library
16#include <MouseController.h>
17
18// Initialize USB Controller
19USBHost usb;
20
21// Attach mouse controller to USB
22MouseController mouse(usb);
23
24// variables for mouse button states
25boolean leftButton = false;
26boolean middleButton = false;
27boolean rightButton = false;
28
29// This function intercepts mouse movements
30void mouseMoved() {
31 Serial.print("Move: ");
32 Serial.print(mouse.getXChange());
33 Serial.print(", ");
34 Serial.println(mouse.getYChange());
35}
36
37// This function intercepts mouse movements while a button is pressed
38void mouseDragged() {
39 Serial.print("DRAG: ");
40 Serial.print(mouse.getXChange());
41 Serial.print(", ");
42 Serial.println(mouse.getYChange());
43}
44
45// This function intercepts mouse button press
46void mousePressed() {
47 Serial.print("Pressed: ");
48 if (mouse.getButton(LEFT_BUTTON)) {
49 Serial.print("L");
50 leftButton = true;
51 }
52 if (mouse.getButton(MIDDLE_BUTTON)) {
53 Serial.print("M");
54 middleButton = true;
55 }
56 if (mouse.getButton(RIGHT_BUTTON)) {
57 Serial.print("R");
58 Serial.println();
59 rightButton = true;
60 }
61}
62
63// This function intercepts mouse button release
64void mouseReleased() {
65 Serial.print("Released: ");
66 if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) {
67 Serial.print("L");
68 leftButton = false;
69 }
70 if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) {
71 Serial.print("M");
72 middleButton = false;
73 }
74 if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) {
75 Serial.print("R");
76 rightButton = false;
77 }
78 Serial.println();
79}
80
81void setup()
82{
83 Serial.begin(9600);
84 Serial.println("Program started");
85 delay(200);
86}
87
88void loop()
89{
90 // Process USB tasks
91 usb.Task();
92}
93
Note: See TracBrowser for help on using the repository browser.