Hello, I’m starter of Processing and Arduino, so sorry for it could be a very beginner’s question.
I tried to googling it and finding some similar cases like me connecting the serial and video playing, but it was hard to solve the problems and adapt to my code.
What i tried was sending specific number of serial from Arduino based on 4 different light sensors. And it worked well, also i checked Processing getting the same serial number when i touched sensor.
But the problem is when processing gets serial, it doesn’t play the video.(I made ‘data’ folder and put video files in it with same name i used in Processing code)
The Processing code is as follows:
import processing.video.*;
import processing.serial.*;
Movie myMovie[];
Serial myPort;
String myString = null;
int index = 0;
void setup() {
size (1280, 800);
myMovie = new Movie[2];
myMovie[0] = new Movie(this, "a.mov");
myMovie[1] = new Movie(this, "b.mov");
myMovie[2] = new Movie(this, "c.mov");
myMovie[3] = new Movie(this, "d.mov");
myPort = new Serial(this, Serial.list()[2], 9600);
myPort.bufferUntil('\n');
}
void draw() {
background(0);
if (myMovie[index].available() ) {
myMovie[index].read();
}
image(myMovie[index], 0, 0);
}
void movieEvent(Movie m) {
m.read();
}
void serialEvent(Serial myPort) {
if(myPort. available() >0){
myString = myPort.readString();
if(myString != null){
println(myString);
}
}
if(myString == "1") {
myMovie[0].loop();
index = 0;
}
if(myString == "2") {
myMovie[1].loop();
index = 1;
}
if(myString == "3") {
myMovie[2].loop();
index = 2;
}
if(myString == "4") {
myMovie[3].loop();
index = 3;
}
}
and this is Arduino code, just in case
const int sensorPin=A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int rate = analogRead(sensorPin);
int sensorValue = analogRead(A0);
int sensorValue2 = analogRead(A1);
int sensorValue3 = analogRead(A2);
int sensorValue4 = analogRead(A3);
if (sensorValue<12){
Serial.println("1");
delay(2000);
}
if (sensorValue2<12){
Serial.println("2");
delay(2000);
}
if (sensorValue3<12){
Serial.println("3");
delay(2000);
}
if (sensorValue4<12){
Serial.println("4");
delay(2000);
}
}
It would be grateful if someone helps the problems.
Thanks for reading and if you have any questions or need more details, please let me know.