Go Down

Topic: mouse tracking servo software (Read 415 times) previous topic - next topic

nooblish

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:

Code: [Select]
#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 :-)

AWOL

#1
Nov 14, 2012, 10:27 am Last Edit: Nov 14, 2012, 10:47 am by AWOL Reason: 1
Code: [Select]
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".

Code: [Select]
int input, 0;
No comma required here.

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

Code: [Select]
int input == serial.Read();
should be
Code: [Select]
int input = serial.Read();
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

nooblish

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?

AWOL

Code: [Select]
if (input == "1") {
...
if (input == 2) {

Maybe, if you sort out your inconsistency.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

nooblish


Maybe, if you sort out your inconsistency.


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

PaulS

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.

PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up