In this recitation, we are asked to create a Processing sketch that controls media by manipulating that media’s attributes using a physical controller made with Arduino. I utilized the idea in recitation8.
For Arduino, I built the circuit by connecting the potentiometer with wires, and used the “Send a Single Value” code. This part went smoothly.
For Processing, the idea of the video came from two cute GIFs I saw before. (credit: @moonlab_studio) They fits so well when put together, therefore I uploaded them into Processing and displayed them using the function “image()”. When the the value of potentiometer turns above 512, then the two puppies will come with an “OK”; when the value is below 512, they will become hostile and show an unfriendly “NO”, which is quite interesting.
Overall speaking, the whole processing went smoothly. The only problem was that the original size of video didn’t fit the screen of processing. So I set the size as (500,500), and put the image in the center.
After making this media controller, I have a better understanding and become more familiar with media playing in Processing.
#CODES:
Processing:
import processing.serial.*; import osteele.processing.SerialRecord.*; import processing.video.*; Serial serialPort; SerialRecord serialRecord; Movie yes; Movie no; void setup() { background(0); size(500, 500); imageMode(CENTER); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 1); yes = new Movie(this, "rinrin.mp4"); no = new Movie(this, "wuwu.mp4"); yes.loop(); no.loop(); } void draw() { serialRecord.read(); int value = serialRecord.get(); if (value==0) { if (yes.available()) { yes.read(); } image(yes, width/2, height/2); } else if (value==1) { if (no.available()) { no.read(); } image(no, width/2, height/2); } }
Arduino:
/* SendMultipleValues This sketch repeatedly sends a record that contains two values: - The first value is the value of `millis()`, modulo 32768. - The second value is the analog value that is read from pin 9. If you attach a potentiometer to that pin, you can control this value by moving the pot. This sketch pairs well with the RecieveMultipleValues example from the Processing SerialRecord library <https://osteele.github.io/Processing_SerialRecord/>. Things to try: - Connect a second potentiometer to the Arduino, and send the values from both potentiometers. - Send the value from another sensor, such as temperature or proximity. by Oliver Steele, 2020-2022 This example code is in the public domain. */ #include "SerialRecord.h" // Change this number to send a different number of values SerialRecord writer(1); void setup() { Serial.begin(9600); //pinMode(6, INPUT); } void loop() { int sensorValue1 = analogRead(A0); if (sensorValue1 >= 512) { writer[0] = 0; writer.send(); } if (sensorValue1 < 512){ writer[0] = 1; writer.send(); } // This delay slows down the loop. This can make it easier to debug the // program. delay(10); }