xxxxxxxxxx
33
let video;
let serial; // Declare a variable for the serial port object
let portName = '/dev/tty.usbmodem101'; // Update with your port name
function setup() {
createCanvas(400, 400);
// Load the video (replace 'your_video.mp4' with the actual video path)
video = createVideo('ezyZip (1).mp4');
video.hide(); // Hide the video until it plays
// Setup serial communication
serial = new p5.SerialPort(); // Create a new instance of the serial port library
serial.open(portName); // Open the port
serial.on('data', gotData); // Attach a 'data' listener to handle incoming data
}
function gotData() {
let data = serial.readLine(); // Read the incoming serial data
if (data.includes('PLAY_VIDEO')) {
video.play(); // Play the video when 'PLAY_VIDEO' message is received
}
}
function draw() {
background(220);
// Draw the video on the canvas
if (video) {
image(video, 0, 0, width, height);
}
}