2012-10-08 19:38:01 +02:00
|
|
|
/*
|
|
|
|
Mouse Controller HID Example
|
|
|
|
|
|
|
|
Shows the output of a USB Mouse connected to the USB
|
|
|
|
controller of an Arduino Due Board.
|
|
|
|
|
|
|
|
created 8 Oct 2012
|
|
|
|
by Cristian Maglie
|
|
|
|
*/
|
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);
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
// This function intercepts mouse movements when a button is pressed
|
|
|
|
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: ");
|
|
|
|
if (mouse.getButton(LEFT_BUTTON))
|
|
|
|
Serial.print("L");
|
|
|
|
if (mouse.getButton(MIDDLE_BUTTON))
|
|
|
|
Serial.print("M");
|
|
|
|
if (mouse.getButton(RIGHT_BUTTON))
|
|
|
|
Serial.print("R");
|
|
|
|
Serial.println();
|
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: ");
|
|
|
|
if (mouse.getButton(LEFT_BUTTON))
|
|
|
|
Serial.print("L");
|
|
|
|
if (mouse.getButton(MIDDLE_BUTTON))
|
|
|
|
Serial.print("M");
|
|
|
|
if (mouse.getButton(RIGHT_BUTTON))
|
|
|
|
Serial.print("R");
|
|
|
|
Serial.println();
|
2012-09-21 17:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
2012-10-08 15:47:13 +02:00
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println("Program started");
|
2012-09-21 17:24:48 +02:00
|
|
|
delay(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// Process USB tasks
|
|
|
|
usb.Task();
|
|
|
|
}
|