Pages: [1]   Go Down
Author Topic: mouse tracking servo software  (Read 357 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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 :-)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26218
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
int input, 0;
No comma required here.

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

Code:
int input == serial.Read();
should be
Code:
int input = serial.Read();
« Last Edit: November 14, 2012, 04:47:06 am by AWOL » Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks AWOL   smiley-lol 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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26218
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (input == "1") {
...
if (input == 2) {
Maybe, if you sort out your inconsistency.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe, if you sort out your inconsistency.

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: