Recitation 10: Image & Video

At the beginning, I checked my tool kit and find a Sliding potentiometer. It will be nice to use it to control the speed of the video because it looks really like a progress bar! Then I thought about what video would be reasonable or interesting with a speed change: everything happens in the cosmos would be a good idea, such as the rotation of earth! So I searched on Wikipedia Commons and found a 30-second nice video. ( Later I found this might be a mistake because 30 seconds is too short. If I use 10 times speed, the video would finished faster than I could realize and start again.)

The circuit was quit easy. I connected the potentiometer to the 5V, GND and A0. When I was writing the code, I followed the instruction and took the examples (SendSingleValue, Movie.Speed and ReceiveSingleValue) as a start. After combing these codes, I took the video. (Sadly, the speed change was not distinct. There may two possible reasons: The video is too short; There is something wrong with the value sending. The second reason is also a problem happening in my final project, and I’m trying hard to solve it.)

This exercise was quite helpful for me to get used to sending and receiving values between Arduino and Processing. I need to use this function in my final project as well, and the information that I need to put a delay on Arduino to ensure Processing receives the value is really important.

Code on Arduino⬇️

#include "SerialRecord.h"

SerialRecord writer(1);
const byte analogPin=A0;
int value;

void setup() {
  Serial.begin(9600);
}

void loop() {
  value=analogRead(analogPin);
  Serial.println(value);
  writer[0] = value;
  writer.send();

  // This delay slows down the loop, so that it runs less frequently. This
  // prevents it from sending data faster than a Processing sketch that runs at
  // 60 frames per second will process it. It also makes it easier to debug the
  // sketch, because values are received at a slower rate.
  delay(20);
}

Code on processing⬇️

import processing.video.*;
import processing.serial.*;
import osteele.processing.SerialRecord.*;

Serial serialPort;
SerialRecord serialRecord;

Movie myMovie;

void setup() {
  background(0);
  fullScreen();
  myMovie = new Movie(this, "Pexels Videos 1851190.mp4");
  //movie from: https://www.pexels.com/video/the-sun-illuminating-earth-s-surface-1851190/
  myMovie.loop();

  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, serialPortName, 9600);
  serialRecord = new SerialRecord(this, serialPort, 1);
}

void movieEvent(Movie movie) {
  myMovie.read();
}

void draw() {

  serialRecord.read();
  int value = serialRecord.get();

  image(myMovie, 0, 0);
  float newSpeed = value/100;
  myMovie.speed(newSpeed);
}



(Thanks for the movie from: https://www.pexels.com/video/the-sun-illuminating-earth-s-surface-1851190/)

Leave a Reply

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