Array of data from Processing to Arduino Problem

I am having trouble sending a constant string of data from Processing to Arduino. I am sending from Processing by the following:

  byte out[] = new byte[14];
  out[0] = byte(servo_one);
  out[1] = byte(servo_two);  
  out[2] = byte(servo_three);
  out[3] = byte(servo_four);
  out[4] = byte(servo_five);
  out[5] = byte(servo_six);  
  out[6] = byte(servo_seven);
  out[7] = byte(servo_eight);
  out[8] = byte(servo_nine);
  out[9] = byte(servo_ten);  
  out[10] = byte(servo_eleven);
  out[11] = byte(servo_twelve);
  out[12] = byte(servo_thirteen);  
  out[13] = byte(servo_fourteen);
  port.write(out);

I am sending the commands out Arduino for servo motor positions. I am using the following code for Arduino:

int nextServo = 0;
int servosPos[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};

Skipping some setup code that is not involved with this problem.

void loop() {

  if(Serial.available()){
    int servoPos = Serial.read();  //set input position to number coming in from processing
    servosPos[nextServo] = servoPos;
    nextServo++;
    if(nextServo > 13)
    {
      nextServo = 0;
    }
    
    Serial1.write(0xFF);  //short protocol command
    Serial1.write(1);  //servo channel number
    Serial1.write(servosPos[0]);  //send the input position
    
    Serial1.write(0xFF);  //short protocol command
    Serial1.write(2);  //servo channel number
    Serial1.write(servosPos[1]);  //send the input position
   
    Serial1.write(0xFF);  //short protocol command
    Serial1.write(3);  //servo channel number
    Serial1.write(servosPos[2]);  //send the input position

and this continues up till servosPos[13]...so there are 14 total. I was thinking that the array of data was stored each time and I could call a particular data by using servosPos#

My code works when I change the Arduino side for only writing out to one servomotor. Could this be a speed issue? I have a 15ms delay for each run on the Processing side to try not to overload Arduino.

When I run the code with all the ports active it looks like the data is getting all out of order. I basically built this code off of some examples that were using an array of 2 numbers.

Thanks!

your double declaring servoPos, 1st as an array of integers and then in the main loop as an integer, Why?

also try using a while loop to govern the serial reads

byte servoPos[14];
int counter=0;

while (Serial.available()) {
      servoPos[counter] = Serial.read();
      counter++;
      if counter > 13 {
          breaK; //exit the loop
        }
 }

Thanks for the response! I tried the while loop method and it is almost working. I am using processing to track a person. The output of my servomotor mechanism appears to be "fighting" itself to track a person. If I move left, it follows left. If I move right, it follows right. However, it stutters constantly like it is getting a very quick short command to move to a different position. I am fairly confident that it is not on the Processing side of things because I am printing the output position commands and they appear correct and consistent.

Arduino Code before void setup() (These are resting positions that I want the motors to start on):

int servosPos[14] = {254, 127, 127, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

Arduino Code loop:

void loop() {

  int counter = 0; 
  
  while (Serial.available())
  {
    servosPos[counter] = Serial.read();
    counter++;
    
    if (counter == 13)
    {
      break; //exit the loop
    }
  }
    Serial1.write(0xFF);  //short protocol command
    Serial1.write(1);  //servo channel number
    Serial1.write(servosPos[0]);  //send the input position
    
    Serial1.write(0xFF);  //short protocol command
    Serial1.write(2);  //servo channel number
    Serial1.write(servosPos[1]);  //send the input position
   
    Serial1.write(0xFF);  //short protocol command
    Serial1.write(3);  //servo channel number
    Serial1.write(servosPos[2]);  //send the input position
    
    Serial1.write(0xFF);  //short protocol command
    Serial1.write(4);  //servo channel number
    Serial1.write(servosPos[3]);  //send the input position

 //etcetera..... for all 14 servo motors.
}

The processing side of things are still the same. The numbers being sent are from 0-255.

I'm kinda new to c++ and hope I don't derail the topic.. but wouldn't this code work and be more efficient?? Or is Serial and Serial1 not available at the same time??

void loop() {

  int counter = 0; 
  
  
  while (Serial.available())
  {
    int channel = counter +1;
    servosPos[counter] = Serial.read();
     Serial1.write(0xFF);  //short protocol command
    Serial1.write(channel);  //servo channel number
    Serial1.write(servosPos[counter]);  //send the input position
    counter++;
    
         if (counter == 13)
         {
             break; //exit the loop
         }
  }
}