Go Down

Topic: Interfacing more than 2 servos using processing ? (Read 799 times) previous topic - next topic

syd_xp

I am in a project of robotic arm in my and I want it to control via usb mouse using processing but it seems that i can control two servos. But I need to control three more. I have driven two servos successfully using this code

Code: [Select]
import processing.serial.*;
Serial port;



void setup()
{
  size(180, 180);
  println("Available serial ports:");
  println(Serial.list());
  port = new Serial(this, Serial.list()[1], 9600);
}

void draw()
{
   port.write(mouseX); //this drives the servo in any angle between 0 to 180
   port.write(mouseY); //this drives the servo in any angle between 0 to 180
}


Is there anyway where i can draw 5 rectangle and control them individually to drive the servos ????

PaulS

Quote
Is there anyway where i can draw 5 rectangle

Yes. In the draw() function.

Quote
and control them individually to drive the servos ????

How do you intend to "control them individually"? How does the size, location, or orientation of a rectangle control the position of a servo? What will the inputs to the size, location, or orientation of the rectangles be?

You've only got one mouse.

syd_xp

Here in my code if the move the mouse along x axis the base servo changes and along Y axis the elbow changes but i need to control other servos too. So i thought that i could draw 5 rect and use them to control each servos. That is each rect can move only between 0 to 180 px to control the angle of servo

PaulS

So, you want the mouse position inside a rectangle, and the number of the rectangle, to be what is used to determine which servo(s) to move and where to move them too.

Should be easy enough. The coordinates of the mouse relative to those of a rectangle can be used to determine if the mouse is inside the rectangle, or not. If it is, the distance from one corner is easy to calculate, and the rectangle number is known.

syd_xp

Yes but i can't find any easy way to do this :(. I was successful in using one rect() and moved it using the mouse cursor to control the servo. If you could help me then it would be great :)

Go Up