arduinoから連絡を受けてサーボを振り終えてからちゃんと次のサーボへの命令をprocessingから送信する

processing

import processing.video.*;
import processing.serial.*;

Capture camera;
Serial myPort;
int first;  // 初回起動判定用

void setup() {
  size(480, 320);

  first = 1;
  myPort = new Serial(this,Serial.list()[1],9600);
  camera = new Capture(this, width, height, Capture.list()[2], 12);
  smooth();
  noStroke();
}

void draw() {
  background(0);
  
  noStroke();
  image(camera, 0, 0);
  camera.loadPixels(); //カメラ画像のpixel情報を読み込み
  if(first==1){ delay(2000); } // 初回起動のみcamera.loadPixelsの処理が遅いため? 少し待つとうまく行く
  
  text(
    "X="+mouseX + " " +
    "Y="+mouseY + " " + 
    "R="+red(camera.pixels[mouseY * width + mouseX])   + " " +
    "G="+green(camera.pixels[mouseY * width + mouseX]) + " " +
    "B="+blue(camera.pixels[mouseY * width + mouseX])  + " "
    ,10
    ,20
  );
  
  stroke(256,0,0);
  strokeWeight(3);
  noFill();
  ellipse(mouseX, mouseY, 20, 20);
  
  if(myPort.read() == 1 || first==1){
    println("AA");
    first = 0;
    if(
       red(camera.pixels[mouseY * width + mouseX])   < 30 &&
       green(camera.pixels[mouseY * width + mouseX]) < 30 &&
       blue(camera.pixels[mouseY * width + mouseX])  < 30
    ){
        myPort.write(1);
    }else{
        myPort.write(0);
    }
  }
  
} 

void captureEvent(Capture camera) {
  camera.read();
}

arduino

#include <Servo.h>

Servo servo1;//サーボのインスタンス
Servo servo2;

void setup() {
  // シリアル通信
  Serial.begin(9600);
  
  //サーボの信号線を3番ピンに接続
  //(PWMピン以外のピンにも接続可)
  servo1.attach(3);
  servo2.attach(6);
}

void loop(){
  if(Serial.available()>0){
    if(Serial.read()==1){
      servo1.write(100);//0~180まで
      delay( 1000 );
      servo1.write(0);//0~180まで
      delay( 1000 );
      Serial.write(1);
    }else{
      servo2.write(100);//0~180まで
      delay( 1000 );
      servo2.write(0);//0~180まで
      delay( 1000 );
      Serial.write(1);
    }
  }
}