Recitation 10: Making a Media Controller

Before this recitation my partner and  I had a clear idea of what our final project was going to be about, we had previously decided that our project was going to be controlled by potentiometers that enable to change properties of an image or object. In this recitation, we expanded our code for our project and modified it to fit the requirements of the recitation. One of our main inspirations was to recreate the illusion of old technology by including the potentiometers to generate a change in the image/object. Our projects main goal is to recreate that idea new doesn’t mean better, today what society is lacking interaction between people and part of this problem is generated by newer technology. Back in time when technology was not developed as much people depended in physical interaction with other humans rather than having a medium to exchange thoughts. This has left the newer generation lacking the capability of physical interaction because they have communicated through technology their entire life. Our project purpose is to create a sense of community by the physical interaction of its users.

 

IMG_6563

 


// ARDUINO to PROCESSING

/*
 * Based on the readStringUntil() example by Tom Igoe
 * https://processing.org/reference/libraries/serial/Serial_readStringUntil_.html
 */

import processing.serial.*;

PImage gene;

String myString = null;
Serial myPort;


int NUM_OF_VALUES = 3;   /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
int[] sensorValues;      /** this array stores values from Arduino **/

int filterNO;

void setup() {
  size(600,600);
  gene = loadImage("gene.jpeg");
  background(0);
  setupSerial();
}


void draw() {
  updateSerial();
  printArray(sensorValues);
  println();
  println();
  println();
  background(0);
  rectMode(CENTER);
  image(gene, mouseX-(sensorValues[1]/4), mouseY-(sensorValues[0]/4), sensorValues[1]/2,sensorValues[0]/2);
  
  if(sensorValues[2] < 150){
    filter(THRESHOLD);
  }
  
  if(sensorValues[2] > 150){
    if(sensorValues[2] < 300){
      filter(GRAY);
    }
  }
  
  if(sensorValues[2] > 300){
    if(sensorValues[2] < 450){
      filter(INVERT);
    }
  }
  
  if(sensorValues[2] > 450){
    if(sensorValues[2] < 600){
      filter(POSTERIZE, 80);
    }
  }

if(sensorValues[2] > 600){
    if(sensorValues[2] < 750){
      filter(ERODE);
    }
  }
  
  if(sensorValues[2] > 750){   
    filter(DILATE);
  }
}


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


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

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

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


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

Leave a Reply