mouse tracking servo software

Hi all. as you can probably tell by my user name, i'm new to arduino.

i intend on making a program on my pc that tracks my mouse movement, and communicates which way i move the mouse via serial.

now my problems are:

  1. i do not know how to program anything. i've never learned how. but i have lots of free time, so i'm willing to learn.
  2. i do not have internet access at home, and i cannot bring a USB stick with the arduino software to verify code (please can someone verify it for me?)
  3. provided i tell the program to communicate mouse movement +x as 1 and -x as 2, would the below code work to move a servo left and right? i intend on having real time control...

here's the code:

#include <servo.h>
Servo ser1;
int input, 0;
int pos, 0;


void Setup() {
serial.begin (9600);
ser1.attach(5);


}
Void Loop() {
int input == serial.Read();

if (input == "1") {
 if(pos<180)
  ++pos;
 }
if (input == 2) {
 if (pos > 0)
 --pos;
 }
ser1.write(pos);
}

thanks for your time :slight_smile:

Void Loop()

You can do yourself a favour, and eyeball the code very carefully.
The C++ is case-sensitive, so will reject "Void" and "Loop". Ditto "Setup".

int input, 0;

No comma required here.

if (input == "1") {

"1" is a single character C string. It will never match a single character.
if (input == '1') { is the correct form.

int input == serial.Read();

should be int input = serial.Read();

Thanks AWOL XD think i should save my code for when i get home...

will this work if there is a constant stream of 0's coming in, and only recieves 1's or 2's when the mouse moves?

if (input == "1") {
...
if (input == 2) {

Maybe, if you sort out your inconsistency.

AWOL:
Maybe, if you sort out your inconsistency.

lol. yeah, i'm working on that...

If you want the servo to track the mouse, you need to understand how a mouse moves. Moving while on the table and moving while in the air are two different things. Moving slowly on the table means one thing. Moving quickly means something else. Just sending information that the movement is to the left or to the right (or up or down) is not going to be enough. You'll need to send how much the mouse moved. You'll need to deal with the fact that the mouse moves relative amounts, while the servo moves absolute amounts.

nooblish:

  1. i do not know how to program anything.

Writing a PC application which captures mouse movements is not trivial. You might want to consider whether you're capable of achieving that before you invest too much effort on the Arduino side.