1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-04 15:24:12 +01:00
Arduino/libraries/USBHost/examples/MouseController/MouseController.ino

94 lines
1.9 KiB
Arduino
Raw Normal View History

2012-10-08 19:38:01 +02:00
/*
Mouse Controller Example
Shows the output of a USB Mouse connected to
the Native USB port on an Arduino Due Board.
2012-10-08 19:38:01 +02:00
created 8 Oct 2012
by Cristian Maglie
http://arduino.cc/en/Tutorial/MouseController
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);
// 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
}
// 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: ");
if (mouse.getButton(LEFT_BUTTON)) {
2012-10-08 15:47:13 +02:00
Serial.print("L");
leftButton = true;
}
if (mouse.getButton(MIDDLE_BUTTON)) {
2012-10-08 15:47:13 +02:00
Serial.print("M");
middleButton = true;
}
if (mouse.getButton(RIGHT_BUTTON)) {
2012-10-08 15:47:13 +02:00
Serial.print("R");
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");
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");
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");
rightButton = false;
}
2012-10-08 15:47:13 +02:00
Serial.println();
2012-09-21 17:24:48 +02:00
}
void setup()
{
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();
}