I'm fairly new to processing and it's my first time involving videos. I am currently using Arduino and Processing to create touch sensitive video player. I have managed to get Arduino to send the readings to Processing and it is reading them. But I can't get the videos to play properly when a sensor is activated (going from 0>1). I think there might be a few things wrong/missing with the code or certain things in the wrong place. A blank screen currently loads when I run the sketch and doesn't change even when activating the sensors. I have the video files in a 'data' folder within the sketch folder so I think they are in the right place. Any help at all is greatly appreciated. Code below;
import processing.serial.*;
import processing.video.*;
Movie movie1;
Movie movie2;
Movie movie3;
//etc.
Serial myPort;
int linefeed = 10; // Linefeed in ASCII
int numSensors = 3; // we will be expecting for reading data from four sensors (CHANGE)
int sensors[]; // array to read the values
int pSensors[]; // array to store the previuos reading, useful for comparing
// actual reading with the last one
String currentMovie;
void setup() {
size(1440, 1080);
println(Serial.list());
// files inside processing folder for this programme
movie1 = new Movie(this, "Sun.mp4");
movie2 = new Movie(this, "Mercury.mp4");
movie3 = new Movie(this, "Venus.mp4");
//etc.
myPort = new Serial(this, Serial.list()[3], 115200);
// read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil(linefeed);
}
void draw() {
// check the sensors and sets the movie to play
if (currentMovie == "") //if nothing is playing
{
if (sensors[0] == 1)
{
//print("Play Movie 1");
currentMovie = "movie1";
movie1.play();
} else if (sensors[1] == 1)
{
print("Play Movie 2");
currentMovie = "movie2";
movie2.play();
} else if (sensors[2] == 1)
{
print("Play Movie 3");
currentMovie = "movie3";
movie3.play();
}
} else
{
// do nothing (if a movie is playing do nothing)
}
// show the movie frames
if (currentMovie == "movie1")
{
if (movie1.available())
{
image(movie1, 0, 0);
} else
{
currentMovie = ""; // if a frame is available, show the next frame. This means once the video ends it will play nothing.
}
} else if (currentMovie == "movie2")
{
if (movie2.available())
{
image(movie2, 0, 0);
} else
{
currentMovie = "";
}
} else if (currentMovie == "movie3")
{
if (movie3.available())
{
image(movie3, 0, 0);
} else
{
currentMovie = "";
}
}
}
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil(linefeed);
// if you got any bytes other than the linefeed:
if (myString != null) {
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
pSensors = sensors;
sensors = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
}
}
void movieEvent(Movie m) {
m.read();
}