In this recitation, I was about to create a Processing sketch that controls media (images or video) by manipulating that media’s attributes using a physical controller made with Arduino. However, too much time was consumed by certain mistakes and I did not finish all bug plugging when the class ended. I intended to make an image of light bulb growing lighter/darker catering to the control of a potentialmeter, but I found the filter function not very satisfactory in achieving that very easily.
My code for processing:
import processing.serial.*;
Serial myPort;
int valueFromArduino;
PImage lightbulb;
void setup() {
size(500, 500);
lightbulb = loadImage(“lightbulb.jpg”);
image(lightbulb, 0, 0);
lightbulb.resize(500, 500);
image(lightbulb, 0, 0);
printArray(Serial.list());
// this prints out the list of all available serial ports on your computer.
myPort = new Serial(this, Serial.list()[1], 9600);
}
void draw() {
image(lightbulb, 0, 0);
//// to read the value from the Arduino
while ( myPort.available() > 0) {
valueFromArduino = myPort.read();
}
println(valueFromArduino);//This prints out the values from Arduino
for(int i=0; i<10; i++){
lightbulb.filter(THRESHOLD, valueFromArduino/1000);
}
}
My code for Arduino:
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(analogRead(A0));
Serial.write(sensorValue);
delay(10);
}