How to use Mouse.Move()

I am using the new Arduino Due to try and move a mouse on my Macbook pro. On the Arduino website it says that I should be able to just add numbers into Mouse.move(xVal, yVal, wheel). I have tried adding numbers in the xVal and yVal positions ranging from .5 to 1000000, but the mouse never moves. I also am trying to use the code that they have on their website as demo code which takes in voltages from analog ports and puts them into the xVal and yVal. I have set it up with two 1K resistors in series with the analog inputs going into A0 and A1 with a voltage supply of 2.1 V. The amount the mouse moves should depend on how much voltage is entering the Arduino, but I am only getting -6 to 6 V coming into the Arduino. Does anyone have any suggestions about how to make the mouse move with Arduino's demo program or just in general? Thank you so much for the help.

Link to Arduino demo code:
http://arduino.cc/en/Reference/MouseMov ... lock&num=1

My code:
void setup()
{
Serial.begin(4800);
Mouse.begin();
}

void loop()
{

if (analogRead(0) > 500)
{
Serial.println("Hello");
Mouse.move(100,100,0);
}
else
{
Serial.println("Goodbye");
Mouse.move(-100,-100,0);
}

sort by: active | newest | oldest
lights01232 years ago

Sorry for recro-posting, but you need to wrap the number in the function char(). Such as:

Mouse.move(char(100),char(100),0);

Can you post the circuit ? I am concerned you have too much voltage on the analogue inputs. The arduino can't read negative voltages either
jwelch2017 (author)  steveastrouk4 years ago
I have 2 1K ohms in series with 2.1V across the analog inputs are in between the two resistors. Both analogs are coming from there. Could that be causing any problems? Im also trying to see if it works on a PC vs a mac. Could that be doing anything? Also on thePC Im using it keeps on saying "no device found on COM6" I have tried udating the software and switching Arduinos to no avail. Any suggestions?
Please post a circuit diagram.
jwelch2017 (author)  steveastrouk4 years ago
here it is.
That will put identical voltages into the two inputs. Is there a common ground between the arduino and the signal source ?
jwelch2017 (author)  steveastrouk4 years ago
I'm not really sure. I have a separate power source providing the voltage across the circuit and it is grounded on the power supply. I believe that is what you are asking for. I don't mind that the inputs are identical, I'm just trying to get it to move on the screen. By signal source do you mean power source?
The power source is the supply to your arduino, the signal source is that which is driving the resistors.

What does this mean ", but I am only getting -6 to 6 V " 6V is too much for the inputs, and -6V will probably kill it.
jwelch2017 (author)  steveastrouk4 years ago
The signal source is separate from the Arduino's power source so they do not have the same ground

I don't think it is in Volts (whatever the Arduino is reading is not in miliVolts either) but when I print out what I am receiving in the arduino from the circuit it prints out a range of small numbers from -6 to 6 when using the arduino website's program. I added a Serial.println(xVal + " + " + yVal) after reading them in. but it's analog read values are in the hundreds in my code. It will print out the words Hello and Goodbye but it won't move the mouse. Do you have any ideas of what I could try while we work on this cause I need to get it working in two weeks? Thank you so much for the help with this, nobody else I have talked to has had no idea so thanks for the help.
AH. There's one of your problems then. Connect the ground of the supply on the signal side to the power ground.

ALSO, you'll have nothing to vary these numbers with - fit a couple of potentiometers to give you something to slide around. What you're reading from the arduino is usually a number 0..1024 scaled against the supply rail.