Control two servos with serial input - help needed

Hi,

I have been fighting with this whole day and without result :confused:
So hopefully someone can help.

I am commanding arduino with serial to give servo coordinates
Serial data is like this:

-224 -400
-224 -400
 199 -230
-224 -400
-33 -204
-224 -400
-69 -51
-200 -148
-224 -400
-130 -240
-224 -400

Where first set is X and second Y
I've been trying to fit 's between and so on,
problem is how to get those number to invidual char's inputx[] and inputy[].

I have managed to control one axel x or y just fine, but havent figuret out how to separate those on serial.read...

This is code for reading just one serial input what i have been using

 if(Serial.available())
  {
    while(i < 4)
    {
      inputx[i] = Serial.read();    
      i++;
    }
    distancex=atoi(inputx);
.
.
.
.

Using Serial.available will return 1 if there is only one character available, but then you read four.
The other three will probably be -1.
You need to check before you read each character, or test "available" to be at least four.

"atoi" works on C strings, so you need to terminate your character array with a zero.

This blog post about a Bitlash solution for driving multiple servos might be of interest:
http://www.entropymouse.com/blog/blog:bitlash_1.1_and_servo_mayhem

Cheers,

-br

http://entropymouse.com

Thanks for replies, but little bit foorum searching paid, found solution.

 if(Serial.available()>0)
   {
      ch = Serial.read(); // Read another character
        i=0;
      while(ch != 13) // 13 is ascii value of carriage return
      {
        inputx[i] = ch; // add the ASCII character to the string;
          i++;
        inputx[i] = '\0';
          ch = Serial.read(); // Read another character        
      }
        i=0;
      ch = Serial.read(); // Read a character
      while(ch != 13) // 13 is ascii value of carriage return
      {
        inputy[i] = ch; // add the ASCII character to the string;
          i++;
        inputy[i] = '\0';
        ch = Serial.read(); // Read another character
      }

  
  
    etaisyysx=atoi(inputx);
    etaisyysy=atoi(inputy);
.
.
.
.