2012-10-08 19:38:01 +02:00
|
|
|
/*
|
2012-10-21 18:36:54 +02:00
|
|
|
Mouse Controller Example
|
2013-10-21 09:58:40 +02:00
|
|
|
|
|
|
|
Shows the output of a USB Mouse connected to
|
2012-10-21 18:36:54 +02:00
|
|
|
the Native USB port on an Arduino Due Board.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-10-08 19:38:01 +02:00
|
|
|
created 8 Oct 2012
|
|
|
|
by Cristian Maglie
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-10-21 18:36:54 +02:00
|
|
|
http://arduino.cc/en/Tutorial/MouseController
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2012-10-22 01:57:23 +02:00
|
|
|
This sample code is part of the public domain.
|
2012-10-08 19:38:01 +02:00
|
|
|
*/
|
2012-09-21 17:24:48 +02:00
|
|
|
|
|
|
|
// Require mouse control library
|
|
|
|
#include <MouseController.h>
|
|
|
|
|
|
|
|
// Initialize USB Controller
|
|
|
|
USBHost usb;
|
|
|
|
|
|
|
|
// Attach mouse controller to USB
|
|
|
|
MouseController mouse(usb);
|
|
|
|
|
2012-10-21 18:36:54 +02:00
|
|
|
// variables for mouse button states
|
|
|
|
boolean leftButton = false;
|
|
|
|
boolean middleButton = false;
|
|
|
|
boolean rightButton = false;
|
|
|
|
|
2012-09-21 17:24:48 +02:00
|
|
|
// This function intercepts mouse movements
|
|
|
|
void mouseMoved() {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("Move: ");
|
|
|
|
Serial.print(mouse.getXChange());
|
|
|
|
Serial.print(", ");
|
|
|
|
Serial.println(mouse.getYChange());
|
2012-09-21 17:24:48 +02:00
|
|
|
}
|
|
|
|
|
2012-10-21 18:36:54 +02:00
|
|
|
// This function intercepts mouse movements while a button is pressed
|
2012-09-21 17:24:48 +02:00
|
|
|
void mouseDragged() {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("DRAG: ");
|
|
|
|
Serial.print(mouse.getXChange());
|
|
|
|
Serial.print(", ");
|
|
|
|
Serial.println(mouse.getYChange());
|
2012-09-21 17:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// This function intercepts mouse button press
|
|
|
|
void mousePressed() {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("Pressed: ");
|
2013-10-21 09:58:40 +02:00
|
|
|
if (mouse.getButton(LEFT_BUTTON)) {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("L");
|
2012-10-21 18:36:54 +02:00
|
|
|
leftButton = true;
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (mouse.getButton(MIDDLE_BUTTON)) {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("M");
|
2012-10-21 18:36:54 +02:00
|
|
|
middleButton = true;
|
|
|
|
}
|
2013-10-21 09:58:40 +02:00
|
|
|
if (mouse.getButton(RIGHT_BUTTON)) {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("R");
|
2012-10-21 18:36:54 +02:00
|
|
|
Serial.println();
|
|
|
|
rightButton = true;
|
|
|
|
}
|
2012-09-21 17:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// This function intercepts mouse button release
|
|
|
|
void mouseReleased() {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("Released: ");
|
2012-12-12 11:47:49 +01:00
|
|
|
if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("L");
|
2012-10-21 18:36:54 +02:00
|
|
|
leftButton = false;
|
|
|
|
}
|
2012-12-12 11:47:49 +01:00
|
|
|
if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("M");
|
2012-10-21 18:36:54 +02:00
|
|
|
middleButton = false;
|
|
|
|
}
|
2012-12-12 11:47:49 +01:00
|
|
|
if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) {
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.print("R");
|
2012-10-21 18:36:54 +02:00
|
|
|
rightButton = false;
|
|
|
|
}
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.println();
|
2012-09-21 17:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2012-10-21 18:36:54 +02:00
|
|
|
Serial.begin(9600);
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.println("Program started");
|
2012-09-21 17:24:48 +02:00
|
|
|
delay(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// Process USB tasks
|
|
|
|
usb.Task();
|
|
|
|
}
|
2012-10-21 18:36:54 +02:00
|
|
|
|