Recitation 10 Documentation: Media Controller (Leon)

Below are codes for Processing:

import processing.serial.*;

String myString = null;
Serial myPort;

int NUM_OF_VALUES = 2;
int[] sensorValues;

PImage img;

void setup() {
size(400, 600);
noStroke();
background(0);
img = loadImage(“Unknown.jpg”);
setupSerial();

}

void draw() {
for (int i=0; i<100; i++) {
//int size = int( random(1, 20) );
int size = int(map(sensorValues[0], 0, 1023, 1, 20));
int x = int( random(img.width) );
int y = int( random(img.height) );
color c = img.get(x, y);
fill(c);
ellipse(x, y, size, size);
}

updateSerial();
printArray(sensorValues);

}

void mousePressed() {
saveFrame(“Unknown.png”);

}

void setupSerial() {
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[ 14 ], 9600);

myPort.clear();
myString = myPort.readStringUntil( 10 ); // 10 = ‘\n’ Linefeed in ASCII
myString = null;

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]);
}
}
}
}
}

 

Below are the codes for Arduino:

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

void loop() {
int sensor1 = analogRead(A0);
int sensor2 = analogRead(A1);

Serial.print(sensor1);
Serial.print(“,”);
Serial.print(sensor2);
Serial.println();

delay(100);
}

For this recitation exercise, I chose to alter an image found on the internet with two potentiometers. I think the hardest part of this exercise is the Processing part. For the Processing part, using array and integers were pretty difficult and hard to understand. However, the Arduino and the circuit was pretty simple. The circuit did not require a lot of wiring and the Arduino coding only needed serial print and connecting it to the right port. Overall, I thought this exercise was an interesting way to changes images and create a different type of art.

Leave a Reply