You can use the Arduino UNO as a mouse, without having to reprogram the chip ATmega, you just have to create a communication through the serial port of the PC to receive the movement or the key you press, and from your program (C, Java, Python, etc. ) read the key, and move the mouse whit a sentence command.
but then you must create a library.
I'm working on that right from my UNO R3.
(You may have to search and replace all instances of "PROGMEM" with "PROGMEM const" to get it to compile, but I'm filing a bug with the author so hopefully that will be fixed soon.)
Hi
I couldn't get this to work on a Leonardo. The example sketch compiles & runs OK.
I added some console prints to make sure the UsbMouse.move routine was executed, however, the mouse doesn't move......
The standard Leonardo Mouse.move works fine, but I don't want to use this, so need the UsbMouse.move working.
Help appreciated.
Arduino Uno can't use the Mouse functions, but if you want to move the mouse with any ardunio (as long as it can use Serial) you can use the Serial to send signals to some other program that runs on your computer.
I personaly prefer using Processing for this, but if you use java it also works. The Robot library alows you to control the mouse and keyboard and it works outside of the window it's running on.
The only problem is you need to install the arduino driver on the computer your using, although i am not sure if you can bypass this.
The following is the code i use to control the mouse with some buttons that move the mouse as if its on a coordinate plane, but you can easily fix this by adding some math although it also depends on what your using to control the mouse.
All this Processing code does is it recieves a Serial communication from the Arduino with some number and then it changes the mouse X and Y positions depending on what number it recieves. You can easily see how to click the mouse by looking at the Robot library's reference which by the way lets you control the mouse and keyboard completely..
import processing.serial.*;
import java.awt.Robot;
import java.awt.AWTException;
Serial port;
Robot robby;
int xx = 50, yy = 50;
int mes;
void setup(){
size(900, 900);
port = new Serial(this, "COM10", 9600);
try{
robby = new Robot();
}catch(AWTException e){
println("Robot class not supported by your system!");
exit();
}
}
void draw(){
while(port.available() > 0){
mes = port.read();
println(mes);
}
mes = mes - '0';
if(mes == 1){
xx-=10;
}else if(mes == 2){
xx+=10;
}else if(mes == 3){
yy+=10;
}else if(mes == 4){
yy-=10;
}
robby.mouseMove(xx, yy);
}
This is the Arduino code that sends the serial message to processing when somone activates a capacitive sensor connected to it which acts just as a normal button.
#include <CapacitiveSensor.h>
CapacitiveSensor left = CapacitiveSensor(3, 2);
CapacitiveSensor right = CapacitiveSensor(5, 4);
CapacitiveSensor down = CapacitiveSensor(7, 6);
CapacitiveSensor up = CapacitiveSensor(9, 8);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
long tot = left.capacitiveSensor(30);
long tot1 = right.capacitiveSensor(30);
long tot2= down.capacitiveSensor(30);
long tot3 = up.capacitiveSensor(30);
if(tot > 500) Serial.print(1);
else if(tot1 > 500) Serial.print(2);
else if(tot2 > 500) Serial.print(3);
else if(tot3 > 500) Serial.print(4);
else Serial.print(0);
}