import processing.video.*; import processing.serial.*; Serial arduino; PImage nolaser; PImage laser; Capture video; int currentState = 0; void setup() { size(640, 240); //So we can display two side-by-side images println(Capture.list()); video = new Capture(this, 320, 240, 1); //About the size my camera is, and on a slow framerate. arduino = new Serial(this, "/dev/tty.usbserial-A4001tLy", 9600); // Start the arduino arduino.write('A'); //Initialize communication println("setup done"); } void draw() { switch( currentState ) { case 0: // laser off, get a frame (when available) if( video.available() ) { video.read(); image(video, 0, 0); arduino.write('G'); currentState = 1; } break; case 1: // waiting for "laser on" confirmation if( arduino.available() > 0 ) { arduino.read(); currentState = 2; } break; case 2: // laser is on, get a frame (when available) if( video.available() ) { video.read(); image(video, 0, 0); arduino.write('F'); currentState = 3; } break; case 3: // waiting for "laser off" confirmation if( arduino.available() > 0 ) { arduino.read(); currentState = 0; // repeat the cycle.. } break; } }