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:
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.
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?)
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);
}
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.
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.