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
|
---|
19 | USBHost usb;
|
---|
20 |
|
---|
21 | // Attach mouse controller to USB
|
---|
22 | MouseController mouse(usb);
|
---|
23 |
|
---|
24 | // variables for mouse button states
|
---|
25 | boolean leftButton = false;
|
---|
26 | boolean middleButton = false;
|
---|
27 | boolean rightButton = false;
|
---|
28 |
|
---|
29 | // This function intercepts mouse movements
|
---|
30 | void 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
|
---|
38 | void 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
|
---|
46 | void 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
|
---|
64 | void 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 |
|
---|
81 | void setup()
|
---|
82 | {
|
---|
83 | Serial.begin(9600);
|
---|
84 | Serial.println("Program started");
|
---|
85 | delay(200);
|
---|
86 | }
|
---|
87 |
|
---|
88 | void loop()
|
---|
89 | {
|
---|
90 | // Process USB tasks
|
---|
91 | usb.Task();
|
---|
92 | }
|
---|
93 |
|
---|