Lab 11 Media Controller (Rudi)

partner: Eliza Cohen

This recitation was exactly as our final project, so we have a class named popUp to open one image file and one sound file for one sensor we detect.

We used a Piezo Disk Vibration Sensor for this.
The sound file is from 99sounds.org , named Project Pegasus made by Bryan Lake aka Sound Author.

We first connected the vibration sensor, and received the sensor from Arduino.

We thought it was digital reception, so we wrote the code like this:

void setup() {
Serial.begin(9600);
pinMode(7, INPUT);
}

void loop() {
if (digitalRead(7) == 1) {
Serial.write(1);
Serial.println(“first sensor works”);
}
}

But we couldn’t detect anything from the sensor, which is when we realized it should be analogRead(Nick helped). So we changed it to analogRead and sent the information to Processing as Serial.println because Serial.write is ASCII (Nick helped).

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

void loop() {
Serial.println(analogRead(A0), DEC);
if (analogRead(A0) > 1) {
Serial.println(1);
}
}

In processing, we have a class and a main tab. The class calls for one image file and one sound file for each input received from arduino.
We have an array for the sound files because we would be calling for 9 sounds. For this recitation we only used one, sounds[0].

Coding was relatively easy because we copied the serial communication code from IMA example.

Here is the video of the sensor working:

 

We used serial communication of processing and arduino to make media (image and sound) pop up by the vibration detected by the sensor. This is an interaction of a user controlling the media, but I thought maybe the media could be controlling the user too, making them move certain ways according to the media shown on screen. For example, games as nintendo WII makes people move according to a gesture shown on screen. If it can be shared both ways, the interaction would be more intertwined and meaningful. One of Random Interactional’s works called Future Self made me reflect more about this relation. This work displays horizontal or vertically moving lights according to the movement of the viewer in front of it. But the movement of the lights also triggers viewers to try different movements and poses to see how the work would react. This is achieving the control and reaction both ways.

---------------------------------Arduino-----------------------------------------------


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

void loop() {
  Serial.println(analogRead(A0), DEC);
  if (analogRead(A0) > 1) {
    Serial.println(1);
  }
}

//delay(100);


---------------------------------Processing------------------------------------

-------------------------------------(main Tab)

import processing.sound.*; //using the sound function
import processing.serial.*; //receiving from arduino
String myString = null;

int NUM_OF_VALUES = 1;   //number of values you are receiving. 
int[] sensorValues;      //this array stores values from Arduino **/
int imageWidth = 510; 
int imageHeight = 598;

SoundFile [] sounds = new SoundFile[9]; //array of soundfiles
popUp Pop; //the class
Serial myPort; 

void setup() {
  //sound array
  sounds[0] = new SoundFile(this, "backgroundMusic.wav");
  
  setupSerial(); // separated the set up for receiving from arduino (copied from the example)
  size(510, 598); 
  background(255);
  Pop=  new popUp("man.jpg.png", sounds[0]); // calling for image and sound
}

void draw() {
  updateSerial();
  //printArray(sensorValues);
  background(255);
  if (sensorValues[0]==1) { //display if vibration is sensed
    Pop.display();
  }
  println(sensorValues[0]);
}


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

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

---------------------------------------------------(sub Tab: class popUp)

class popUp {
  //components
  PImage img; //image
  SoundFile s; //sound

  //constructor
  popUp(String imageName, SoundFile soundName) {  //loading an image and a sound file
    img = loadImage(imageName);
    s = soundName;
   }

  //display the image and play the music
  void display() {
    pushMatrix();
    image(img, 0, 0, 600, 600);
    s.play();
    popMatrix();
  }
}

One thought on “Lab 11 Media Controller (Rudi)

Leave a Reply