In this week’s recitation, I wanted to add a filter to my video and change its speed by using the Potentiometer. The original video is blue and I made it greener.
I attached 3 cables connecting the Arduino and the Potentiometer, one to the A0 on the board, one to 5V, and one to the Ground.
Here is the final coding in Arduino: it will send the signal to Processing and make the circuit work.
#include "SerialRecord.h" SerialRecord writer(1); void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(A0); writer[0] = sensorValue; writer.send(); // This delay slows down the loop, so that it runs less frequently. This can // make it easier to debug the sketch, because new values are printed at a // slower rate. delay(10); }
The coding in Processing: I should define the variable at the beginning and apply the SerialRecord in the library to connect the program with the Arduino.
import processing.serial.*; import osteele.processing.SerialRecord.*; import processing.video.*; Movie myMovie; Serial serialPort; SerialRecord serialRecord; void setup() { fullScreen(); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 1); myMovie = new Movie(this, "1.mp4"); myMovie.loop(); } void draw() { background(0); serialRecord.read(); int value = serialRecord.get(); if (myMovie.available()) { myMovie.read(); } float a = map(value, 0, 1024, 0, 255); float b = map(value, 0, 1024, 0, 255); float newSpeed = map(a, 0, width, 0.1, 5); myMovie.speed(newSpeed); tint(a, b, 0); image(myMovie, 0, 0); }
Actually, I first used the button and decided to change the filter of the video by pressing the button. But I failed to connect it correctly with the Arduino. I didn’t do anything with the Button and it continuously sends the signal to my Processing. I had no time left, so I changed it into the Potentiometer.
When I switch it, the video will play faster and turn Greener or play slower and turn darker.
Let us see the video: