xxxxxxxxxx
134
let serial;
let portName = "COM19";
let inData;
let videoli = [];
function setup() {
noCanvas();
for (let i = 0; i < 23; i++) {
videoli[i] = createVideo("vid" + "/" + i + ".mp4", readyo);
}
console.log(videoli);
serial = new p5.SerialPort();
serial.on("list", printList);
serial.on("connected", serverConnected);
serial.on("open", portOpen);
serial.on("data", serialEvent);
serial.on("error", serialError);
serial.on("close", portClose);
serial.list();
serial.open(portName);
//inData = 10;
}
// function draw() {
// console.log(inData);
// }
function printList(portList) {
for (var i = 0; i < portList.length; i++) {
console.log(i + portList[i]);
}
}
function serverConnected() {
console.log("connected to server.");
}
function portOpen() {
console.log("the serial port opened.");
}
function serialEvent() {
inData = Number(serial.read());
if (inData == 10) {
//dong-dong: 4s
changeVideo(0);
} else if (inData == 100) {
//开灯25s
changeVideo(1);
} else if (inData == 200) {
//开灯之后的loop:7s
changeVideo(2);
} else if (inData == 54) {
//风吹出密码盒子:13s
changeVideo(4);
} else if (inData == 64) {
//绳子拉出密码盒子:13s
changeVideo(3);
} else if (inData == 74) {
//锤子锤出cipher box:13s
changeVideo(5);
} else if (inData == 144) {
//密码盒出现后loop:13s
changeVideo(6);
} else if (inData == 154) {
//大风吹吹报纸:13s
changeVideo(7);
} else if (inData == 164) {
//绳子拉了一下嘎吱嘎吱无事发生:6s
changeVideo(8);
} else if (inData == 174) {
//锤子拉了一下蹦无事发生:7s
changeVideo(9);
} else if (inData == 244) {
//风吹后的loop:4s
changeVideo(10);
} else if (inData == 254) {
//风吹起来了但无事发生:12s
changeVideo(11);
} else if (inData == 8) {
//拉出了个密码箱子:14s
changeVideo(12);
} else if (inData == 18) {
//锤了一下无事发生:8s
changeVideo(13);
} else if (inData == 88) {
//有密码箱子的loop:5s
changeVideo(14);
} else if (inData == 98) {
//风吹起来了但无事发生:5s
changeVideo(15);
} else if (inData == 108) {
//拉了一下无事发生:5s
changeVideo(16);
} else if (inData == 118) {
//箱子锤开了!!:14s
changeVideo(17);
} else if (inData == 188) {
//绝望loop:5s
changeVideo(18);
} else if (inData == 198) {
//懒得理风:5s
changeVideo(19);
} else if (inData == 208) {
//懒得理拉:4s
changeVideo(20);
} else if (inData == 218) {
//懒得理锤:4s
changeVideo(21);
} else if (inData == 32) {
//ending:50s
changeVideo(22);
}
}
function changeVideo(x) {
for (let i = 0; i < 23; i++) {
if (i !== x) {
videoli[i].hide();
videoli[i].pause();
}
}
videoli[x].show();
videoli[x].size(windowWidth,windowHeight);
videoli[x].loop();
}
function serialError(err) {
console.log("Something went wrong with the serial port. " + err);
}
function portClose() {
console.log("The serial port closed.");
}
function readyo() {
print("ready");
}