0

So I have a java program that picks up the mouses x and y coords on the display and I would like to send those to my arduino and then move my two servos to those locations (I have two servos ontop of each other, one for x and one for y).

The java (processing) code i have is below

void draw(){ //same as loop in arduino
 background(52, 152, 219); // background color of window (r, g, b) or (0 to 255)
 //lets give title to our window
 fill(0, 255, 0); //text color (r, g, b)
 textFont(font);
 text("Ripple Effect Maker", 80, 30); // ("text", x coordinate, y coordinat)
 ellipse(mouseX, mouseY, 33, 33);
 int x = mouseX;
 int y = mouseY;
 port.write(x+":"+y);
 println(x+":"+y);
 //println("y="+y);
 delay(100);
}

I don't have much arduino code because I can't seem to find a way to split the data into two seperate variables and then move the servos to their corresponding variables.

Thanks for the help!

asked Oct 17, 2019 at 3:03
1

1 Answer 1

1

Your problem is that you aren't providing anything to split the data on. You just send the X and y coordinates with a : between X and y. There's nothing between the y and the next X.

By changing the line

port.write(x+":"+y);

To

port.write(x+":"+y+"\n");

You then get the linefeed character to split your data on.

answered Oct 17, 2019 at 11:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.