Recitation 10: Media Contoller by Gloria Yixuan Liu

For this recitation, I wanted to pre-explore a little bit about the animation part for my final project, with this given opportunity of using the Processing and the Arduino to control a media. Therefore, I used a sketch drawn by myself with my laptop.

Image

First of all, I opened the given model for connecting the Arduino to the Processing. Then I uploaded the picture into the Processing, set the size, the background, but later found out that I forgot to define the image using “whale = loadImage(“whale.jpg”) after loading the image. Then I connected the circuit using one potentiometer and wrote the code for the Arduino part, which is pretty simple since I only need to write the analog in pin for the potentiometer. Then I went back to the Processing and modified the image with “if” and “else if” so that the size and the filter of my image can be changed in terms of the value from the potentiometer, from 0 to 1023.

Then I ran the code, but it seemed that the printed number for the potentiometer did not change in the Processing. With Tristan’s help, I changed the “Serial.print” into “Serial.println” in the Arduino part, otherwise, the system would be unable to recognize the new value given by the potentiometer.

I ran the code again, but the white background in my image was ugly, Therefore I used the Photoshop to delete the background of my original image with Nick’s help.

Finally, my whale can get bigger or smaller or would be added with a filter as I twisted the potentiometer.

According to Computer Vision for Artist and Designers, the way that technology was used in my project is the computer vision algorithms, through which the digital image can be modified into different art genre enabled by the vision functionalities. With this technology, the variability of creation can be generated, since a fixed prototype of an artwork can be modified into different versions by different audience, through the interaction with the computer. This method empowered my project since I can turn a fixed artwork into different versions in terms of the settings that I want to put my project in.

Code:

Processing part:

PImage whale;
import processing.serial.*;
String myString = null;
Serial myPort;
int NUM_OF_VALUES = 1; /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
int[] sensorValues; /** this array stores values from Arduino **/
void setup() {
size(1023, 1023);
background(255);
setupSerial();
whale = loadImage(“whale.jpg”);//////
}
void draw() {
background(255);
updateSerial();
printArray(sensorValues);
println(sensorValues);
if (sensorValues[0]<400) {
image(whale, 0,0,400, 400);
} else if (sensorValues[0]>=400 && sensorValues[0]<700) {
image(whale, 0, 0, sensorValues[0], 0.8*sensorValues[0]);
} else if (sensorValues[0] >=700 && sensorValues[0]<1023) {
image(whale, 0,0, sensorValues[0], 0.8*sensorValues[0]);
filter(INVERT);
}
}
void setupSerial() {
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[ 0 ], 9600);
sensorValues = new int[NUM_OF_VALUES];
}
void updateSerial() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil( 10 ); // 10 = ‘\n’ Linefeed in ASCII
if (myString != null) {
String[] serialInArray = split(trim(myString), “,”);
if (serialInArray.length == NUM_OF_VALUES) {
for (int i=0; i<serialInArray.length; i++) {
sensorValues[i] = int(serialInArray[i]);
}
}
}
}
}

Arduino Part:

void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValues = analogRead(A0);
Serial.print(sensorValues);
Serial.println(“,”); //print the new ln!!!
delay(10);
}

Leave a Reply