talofer99 icon

Activating a video in Processing using serial

talofer99 | PRO | 04/23/18 11:24:09 AM UTC | 0 ⭐ | 320 👁️ | Never ⏰ | []
C |

1.42 KB

|

None

|

0 👍

/

0 👎

import processing.video.*;
import processing.serial.*;
 
Serial arduino;
 
Movie movie;
boolean playing = false;
boolean starting = true;
 
void setup() {
  //size(1024,576);
  fullScreen();
  movie = new Movie(this, "test1.mp4");
  println(Serial.list());
  String port = Serial.list()[Serial.list().length-1];
  println("using port:" + port);
  arduino = new Serial(this, port, 9600);
}
 
void draw() {
  background(0);
  fill(255,0,0);
  textSize(50);
  if(frameCount < 120) {
    text("Calibrating...", (width-textWidth("Calibrating..."))/2,height/2);
  }
  else if(frameCount > 120 && frameCount < 180) {
    text("OK Computer", (width-textWidth("OK Computer"))/2, height/2);
  }
 
  //translate(width/2, height/2);
  //rotate(PI/2.0);
  //translate(-height/2, -width/2);
  
  if ( arduino.available() > 0) {
    int val = arduino.read();
    switch(val) {
      case 'p':
      play_movie();
      break;
      case 's':
      stop_movie();
      break;
    }
  }
  
  if(playing) {
    image(movie, 0, 0, width, height);
    // image(movie, 0, 0, height, width);
  }
}
 
void movieEvent(Movie m) {
  m.read();
}
 
void play_movie() {
    movie.loop();
    playing = true;
}
 
void stop_movie() {
    movie.stop();
    playing = false;
}
 
// debug
void keyPressed() {
  if(keyCode == ' ') {
    if(!playing) {
      play_movie();
    }
    else {
      stop_movie();
    }
  }
}

Comments