MovieSystem

// http://processing.org/discourse/yabb2/YaBB.pl?num=1232023541
import processing.serial.*;
Serial myPort;

String unparsedReading;
float wheelValue;
float pedalValue;

import processing.video.*;

MovieManager movieMan;
boolean init = false;

float movieSpeed = 1.0;
float movieSpeedDelta = 0.1;

void setup() {
  size(1920,720);
  movieMan = new MovieManager(this);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void initialize() {
  movieMan.addMovie("/Users/rose/Documents/Processing/MovieSystem/data/DSC_0844.AVI");
  movieMan.addMovie("/Users/rose/Documents/Processing/MovieSystem/data/shanghai.MP4");
  movieMan.addMovie("/Users/rose/Documents/Processing/MovieSystem/data/DSC_1377.avi");
  movieMan.addMovie("/Users/rose/Documents/Processing/MovieSystem/data/nightdesert.AVI");
   movieMan.addMovie("/Users/rose/Documents/Processing/MovieSystem/data/VID00096.MP4");
  movieMan.addMovie("/Users/rose/Documents/Processing/MovieSystem/data/DSC_1068.AVI");

  movieMan.initialize();
  init = true;
}

void draw() {
  if(!init) {
    initialize();
  }
  background(0);
  movieMan.draw();

  unparsedReading = trim(unparsedReading);
  if(unparsedReading != null) {
      int[] sensorValues = int(split(unparsedReading,","));

      if(sensorValues.length >= 2) {
        wheelValue = map(sensorValues[0], 0, 1023, -30, 30);
        pedalValue = map(sensorValues[1], 0, 1023, 0, 3);
      }

      if(pedalValue < 0.1) {
        pedalValue = 0.1;
      }
      //println(movieSpeed);
      //movieSpeed = pedalValue;
      movieMan.setAllSpeeds(pedalValue);

      println(pedalValue);
      movieMan.translateX += (int)wheelValue;
 }
}
void serialEvent (Serial myPort) {
    // get the ASCII string:
    String inString = myPort.readStringUntil('\n');
    if(inString != null) {
      unparsedReading = inString;
    }
}

void keyPressed() {
  if(key == '1') {
    movieMan.translateX -= 50;
  }
  else if(key == '2') {
    movieMan.translateX += 50;
  }
  else if(key == '3') {
    movieSpeed -= movieSpeedDelta;
    if(movieSpeed < 0.1) {movieSpeed = 0.1;}
    movieMan.setAllSpeeds(movieSpeed);
  }
  else if(key == '4') {
    movieSpeed += movieSpeedDelta;
    if(movieSpeed > 10.0) {movieSpeed = 10.0;}
    movieMan.setAllSpeeds(movieSpeed);
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>