Video playback if

Hi all.
I’m trying to use my Arduino Serial to control video play in Processing.
What I want to achieve is video play when value(Arduino) is higher than 2.
And when not (lower than 2) I wanted my video to playback(rewind) to its first frame.

But somehow, this code plays nothing…
Any suggestions?
Would really appreciate it.


import processing.video.*;
import processing.serial.*;

Serial mySerial;
Movie myMovie;
String myString = null;
int nl = 10;
float myVal;



void setup() {
 fullScreen();
  frameRate(20);
  myMovie = new Movie(this, "loop3.mov");
   println(myMovie.duration());
  
   
  String myPort = Serial.list() [2];////
  mySerial = new Serial(this, myPort, 9600);////
 myMovie.play();
 myMovie.jump(0.01);
 

}

void movieEvent(Movie m) {
  m.read();
}

void draw() {
  
  
  while (mySerial.available() > 0) {
    myString = mySerial.readStringUntil(nl);
    if (myString != null) {
      background(0);
      myVal = float(myString);   } }
      
 
  myMovie.pause();
  if (myVal >2){
    myMovie.speed(1);
  myMovie.play();}
  
else if(myVal < 2) {
    myMovie.speed(-1);
    myMovie.play();
}
  image(myMovie, 0, 0,displayWidth,displayHeight);


}


btw. serial communication works fine.

Take a look at your logic. If myVal == 2, it won’t play. Change your else if statement to else.

Also try using debugger or println to make sure that myVal is being updated properly from serial.