Recitaition 9 by Tya Wang (rw2399)

For this week’s exercise, I created a program that changes the color of an image based on the value sent back from Arduino. The program works like this:

The color changes smoothly because I changed the colorMode into HGB and mapped value sent back by a potentiometer, which is between 0 and 1023, into between 0 and 360.

I think this program can be used in the future to make a digital color filling book, where you choose a section and then decide what color you want to fill in this section. This may help people reduce pressure when playing with it and creat their own art work.

Here is the code on processing attached:

import processing.serial.*;
PImage photo;


Serial myPort;
int valueFromArduino;


void setup() {
  size(500, 413);
  photo = loadImage("bob.jpg");
  photo.loadPixels();
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
}


void draw() {
  tint(valueFromArduino, 100, 100);
  image(photo, 0, 0);
  
}

Recitation 9—Vivien Hao

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

Recitation 9: Media Controller by Yu Yan (Sonny)

Introduction:

In this recitation, we were asked to build a connection between Arduino and Processing to control a media/image, which is similar to what we did for last recitation. 

Exercise:

For this exercise, I used two potentiometers to control two parameters in Processing, one is “tint”, another is the level of “BLUR” in “filter”. Also, by mapping them into a certain amount, the parameter can stay in a reasonable range and change the color and effect of my image. The final effect is that for the potentiometer that controls the filter, the bigger value it shows, the more blurry the image would be; for the potentiometer that controls the “tint”, I can change the color of the image by rotating the potentiometer to different value.

The process of setting the parameter for “tint” is quite smooth. However, when I coded for “filter”, I was thinking about creating an array to store a few different kinds of filters and when I press a button, it would randomly display a filter covered on the image. But after trying for several times, it seems that I cannot use the array in this way. So I gave up on this idea and change into using a potentiometer to control a parameter in one specific filter. 

The code for Processing and Arduino is as follows.

Processing:

PImage photo;

import processing.serial.*;
String myString = null;
Serial myPort;

int NUM_OF_VALUES = 2;
int[] sensorValues = new int [NUM_OF_VALUES];
float x;
float y;

void setup(){
  size(1000,600);
  color(HSB);
  photo = loadImage("daniel touchin.jpg");
  setupSerial();
}

void draw(){
  updateSerial();
  printArray(sensorValues);
  x = map(sensorValues[0],0,1023,0,360);
  y = map(sensorValues[1],0,1023,0,10);
  tint(x,100,100);
  image(photo,0,0);
  filter(BLUR, y);
}


void setupSerial() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 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( 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]);
        }
      }
    }
  }
}

Arduino:

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

void loop() {
int sensor1 = analogRead(A0);
//int sensor2 = digitalRead(9);
int sensor3 = analogRead(A2);

// keep this format
Serial.print(sensor1);
Serial.print(","); // put comma between sensor values
// Serial.print(sensor2);
// Serial.print(",");
Serial.print(sensor3);
Serial.println(); // add linefeed after sending the last sensor value

// too fast communication might cause some latency in Processing
// this delay resolves the issue.
delay(100);
}

Reflection:

The reading Computer Vision for Artist and Designers really gives me some enlightenment for my final project. But first of all, it shows me the background of computer vision, which is what we’re using during the class. I learned many different aspects and types of computer vision techniques. The project mentioned in the reading that really intrigued me is Messa di Voce by Golan Levin and Zachary Lieberman, which “uses a set of vision algorithms to track the locations of the performers’ heads…… also analyses the audio signals coming from the performers’ microphones”. I like how this project interact with the audience because tracking people’s heads and turning the sound they make into the output displayed on the screen is very novel and interesting for me. This is a kind of interaction that I cannot think of with my shallow knowledge and creativity. But somehow it inspires me that there can always be an innovative way of interaction that I am able to come up with. For my final project, the computer vision technique that my partner and I want to apply is “Detecting Motion”, also mentioned in the reading. This is a very basic technique but also can be really attractive and intriguing. I would use the example project mentioned in the reading as a reference to improve my final project and try to apply more creative and interesting interaction in the project.

Recitation 9 by Christina Bowllan

Arduino Code

// For sending multiple values from Arduino to Processing

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

void loop() {
int sensor1 = analogRead(A0);
int theMappedValue = map(sensor1, 0, 1023, 0, 255);

// keep this format
Serial.write(theMappedValue);
//Serial.println(); // add linefeed after sending the last sensor value

// too fast communication might cause some latency in Processing
// this delay resolves the issue.
delay(100);
}

Processing Code

// IMA NYU Shanghai
// Interaction Lab
// This code receives one value from Arduino to Processing 

import processing.serial.*;


Serial myPort;
int valueFromArduino;
PImage photo;
float opacity; 



void setup() {
  size(500, 413);
  background(0);
 photo = loadImage ("bob.jpg");

  // this prints out the list of all available serial ports on your computer.

  myPort = new Serial(this, Serial.list()[ 15 ], 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.
}


void draw() {
  // to read the value from the Arduino
   //float opacity = map (valueFromArduino,0,1023,0,255); //we need a float because we want processing to catch all the numbers from arduino 
  while ( myPort.available() > 0) {
    valueFromArduino = myPort.read();
  }
   printArray(Serial.list());
   println(valueFromArduino);
   //tint (0,0,255, opacity);
  image(photo, 0,0);
  
  if (valueFromArduino <150){
   tint(255,0,0); 
  } else if(valueFromArduino > 200) {
    tint (0,255,0);
  }

 
 //This prints out the values from Arduino
}

During this week’s recitation, I used a potentiometer to tint the image from red to green. The main challenge I faced was inserting an “if else” statement in processing. At first, when I did not have the “if else” statement, the Spongebob image would tint red but would not change after that. However, once I added the “if else” statement,  I told processing when the colors should change, so then the image tinted colors. 

In this week’s reading, the Suicide Box relates well to what we did in this task. Whenever the camera sensed a vertical motion, then it would record people falling and track information. This reminds me of the “if else” statement that we used in this task to control the color tint. In both projects, we are giving the computer parameters to know when they should perform tasks. 

Recitation 9–Media Controller–Ketong Chen

Processing

During the recitation, I used the potentiometer to control the speed of the video. Since I only need one value from the potentiometer, I use the one value sample code. During the process, I first have difficulty putting the video in my data folders, but later I found that I actually download the wrong format of the video. It should always be .mp4 or .mov. Here are the codes:

import processing.serial.*;
import processing.video.*;
Movie myMovie;

Serial myPort;
int valueFromArduino;


void setup() {
  size(240, 426);
  background(0);

  printArray(Serial.list());
  // this prints out the list of all available serial ports on your computer.

  myPort = new Serial(this, Serial.list()[ 3 ], 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.


  myMovie = new Movie(this, "Lilly.mp4");
  myMovie.loop();
}
void movieEvent(Movie movie) {
  myMovie.read();  
}
void draw() {
  // to read the value from the Arduino
  while ( myPort.available() > 0) {
    valueFromArduino = myPort.read();
  }
  println(valueFromArduino);//This prints out the values from Arduino
  image(myMovie, 0, 0,240,426);   
  float newSpeed = map(valueFromArduino, 0, width, 0.1, 5);
  myMovie.speed(newSpeed);
}

Arduino

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

void loop() {
int sensorValue = analogRead(A0) / 4;
Serial.write(sensorValue);

// too fast communication might cause some latency in Processing
// this delay resolves the issue.
delay(10);
}

video:

After reading the text Computer Vision for Artist and Designers 

I understand that the computer vision technology was once constrained in military and law enforcement purposes. But it can also be used by interactive media artists to build vision-based detection projects to benefit the society. I was amazed by the project Suicide Box by the Bureau of Inverse Technology (Natalie Jeremijenko and Kate Rich) mentioned in the reading. It is a motion­detection video system and track the vertical motion of the jumpers to record the data. It let me think about the moral problems and questions we created when we make a project and after we have created the project, what is the relation between the maker and the project as well as the people interact with it. The project should be meaningful which contains the thoughts of the artists or better to reveal or solve some real problems. I hope I can use processing and Arduino to make a meaningful final project.