import processing.serial.*;
import processing.video.*;
Serial port;
Movie movNor, movTrg;
float loopPos = 0.2;
String movFile1 = "6162.mov";
String movFile2 = "5824.mov";
int scrW, scrH;
int sensorChk = 0;
void setup() {
size(1280, 720);
scrW = width;
scrH = (int)(width *9/16);
port = new Serial(this, "/dev/cu.usbmodem141011", 115200);
movNor = new Movie(this, movFile1);
movTrg = new Movie(this, movFile2);
movNor.play();
movTrg.pause();
}
void draw() {
if(sensorChk == 1) {
image(movTrg, 0, 0, scrW, scrH);
} else {
image(movNor, 0, 0, scrW, scrH);
}
if(movNor.duration() - movNor.time() < loopPos) {
movNor.jump(0);
}
}
void movieEvent(Movie m) {
m.read();
}
void serialEvent(Serial port) {
String str = port.readStringUntil('\n');
if(str != null) {
String s = trim(str);
if(s == "DETECT") {
sensorChk = 1;
movTrg.jump(0);
movTrg.play();
} else if(s == "NOT DETECT") {
sensorChk = 0;
movTrg.pause();
movTrg.jump(0);
}
}
}