For this recitation exercise, I have decided to include one of my favorite song cuts. While I move the potentiometer, the image of the video would change a little bit.
This is my Processing code:
import processing.serial.*; import processing.video.*; Movie myMovie; String myString = null; Serial myPort; int NUM_OF_VALUES = 1; int[] sensorValues; void setup() { size(500, 500); myMovie = new Movie(this, "JJ Lin.mp4"); myMovie.play(); setupSerial(); } void draw() { updateSerial(); printArray(sensorValues); float hcy = map (sensorValues[0],255, 1023, 0,100); if (myMovie.available()) { myMovie.read(); } tint(hcy, random(100), random(800)); image(myMovie, 0, 0); } void setupSerial() { printArray(Serial.list()); myPort = new Serial(this, Serial.list()[ 1 ], 9600); // WARNING! // You will definitely get an error here. // Change the PORT_INDEX to 0 and try running it again. // And then, check the list of the ports, // find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----" // and replace PORT_INDEX above with the index number of the port. myPort.clear(); // Throw out the first reading, // in case we started reading in the middle of a string from the sender. myString = myPort.readStringUntil( 5 ); // 10 = '\n' Linefeed in ASCII myString = null; sensorValues = new int[NUM_OF_VALUES]; } void updateSerial() { while (myPort.available() > 0) { myString = myPort.readStringUntil( 10 ); 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]); } } } } }
This is my Arduino code
// IMA NYU Shanghai
// Interaction Lab
// For sending multiple values from Arduino to Processing
void setup() {
Serial.begin(9600);
}
void loop() {
int sensor1 = analogRead(A0);
Serial.print(sensor1);
Serial.println();
delay(100);
}