Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Loop Video with values sent from Arduino.
- *
- * Using an Arduino and Potentiometer, contro the playback speed of a video
- * Recieve values using Serial I/O library
- */
- import processing.video.*;// import video library
- import processing.serial.*;// import serial library
- Movie myMovie; // The movie object
- float timeJump = 0.0; // amount of time that is displaced when scrubbing the movie in reverse
- float timePrevious = 0.0; // the last position of the playhead
- float timeFuture = 0.0; // the future position of the playhead
- float videoSpeed = 0.0; // the speed at which the video plays
- float maxSpeed = 5.0;
- float minSpeed = -5.0;
- Serial myPort; // The serial port
- void setup() {
- size(640, 480, P2D);
- background(0);
- // Load and play the video in a loop
- myMovie = new Movie(this, "station.mov");
- myMovie.loop();
- println(Serial.list());
- myPort = new Serial(this, Serial.list()[0], 9600);
- }
- void movieEvent(Movie myMovie) {
- myMovie.read();
- }
- void draw() {
- // tint(255, 30);
- if(videoSpeed < 0) {
- timeJump = myMovie.time() - timePrevious;
- timeFuture = myMovie.time() + timeJump;
- if(timeFuture <= 0) {
- // we only need to ajust the playhead if the playhead goes past
- // the beginning of the movie in reverse
- float newBackwardsTime = myMovie.duration() + timeFuture;
- myMovie.jump(newBackwardsTime);
- }
- }
- myMovie.speed(videoSpeed);
- image(myMovie, 0, 0, width, height);
- timePrevious = myMovie.time();
- }
- /**
- * serialEvent
- *
- * This function access the values coming in from the serial port
- * It assigns the values to the play speed of the video, called videoSpeed
- * The videoSpeed has a range of -5x to +5x normal playing speed
- * These values are determined by the minSpeed and maxSpeed variables
- * If you alter them you can change the range of speed the video will play
- * For this to work, an Arduino must be sending one byte through the serial port
- */
- void serialEvent (Serial myPort) {
- // get the byte:
- int inByte = myPort.read();
- videoSpeed = map(inByte, 0, 255, minSpeed, maxSpeed);
- // print it:
- println(inByte);
- }
- // This can be tested with using the keys if you are unable to access and Arduino and potentiometer
- // The UP key increases the speed and the DOWN key decreases the speed
- void keyPressed() {
- if(keyCode == UP) {
- videoSpeed += 0.1;
- videoSpeed = constrain(videoSpeed, minSpeed, maxSpeed);
- }
- if(keyCode == DOWN) {
- videoSpeed -= 0.1;
- videoSpeed = constrain(videoSpeed, minSpeed, maxSpeed);
- }
- println("adjusted videoSpeed with keys to: " + videoSpeed);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement