Relative Mode
One of the capabilities of these boards is to emulate a mouse. A mouse is typically a relative mode device. If you call Mouse.move(1,1), it will move 1 pixel right and 1 pixel down from where ever it currently is. Mouse.move(-5, 10) will move left 5 and down 10. Note that your board has no way of knowing where the mouse is at any point in time.
Absolute Mode
Fortunately, there is an absolute mode available to the mouse. Once enabled, performing a Mouse.move(1,1) will move the mouse to the very top left corner of the display, no matter where it currently is, or what resolution it is in. Likewise, Mouse.move(100,100) will move it to the bottom right corner of the display. Mouse.move(50,50) is the center (based on the LOGICAL_MAXIMUM in HID.cpp)
The arduino IDE can support absolute mouse mode. However it requires modifying one of the IDE files. This solution is for Arduino 1.0 and has not been tested on prior versions.
Procedure:
1. Kill your Arduino IDE if it is running.
2. Cd to (your arduino directory)/hardware/arduino/cores/arduino directory.
3. Copy your HID.cpp file somewhere safe that you can restore it later if you want to use relative mouse mode again.
4. Copy the attached HID.cpp replacement code below and paste it into your (arduino directory)/hardware/arduino/cores/arduino/ directory.
5. Copy the example sketch into the Arduino IDE and compile it.
6. Download the sketch to your atmega32u4 or similar board.
7. Within about 5 seconds, the mouse should start moving around the screen.
Now when you use the normal Mouse.move(x, y) it will use absolute coordinates (vice the default relative coordinates). Note that LOGICAL_MINIMUM(1) and LOGICAL_MAXIMUM(100) in HID.cpp map to the coordinate space of any display you connect to. So your sketches will always use coordinates between LOGICAL_MINIMUM and LOGICAL_MAXIMUM.
Here's the example sketch that simply moves the mouse left to right, and top to bottom:
Example Sketch
Code: Select all
void setup(){
}
void loop(){
for(int y = 1; y <= 100; y++){
for(int x = 1; x <= 100; x++){
delay(100);
Mouse.move(x, y);
}
}
}