Patricia Adler | ITP Blog

Human Wind Chime – Final Piece

Enjoy the following video of our final piece in action – now including sound:

human wind chime final from Patricia Adler on Vimeo.

And our final code – in Arduino and Processing:

------------------------
ARDUINO CODE
------------------------
/* Define variables
 ************************************/
// Sensor threshold to tell us if ball is moving
// (usually does not break 10, but let's make it 15 to be safe)
int sensorThreshold = 4;

// Analog Inputs
int analog1 = 0;
int analog2 = 1;
int analog3 = 2;
int analog4 = 3;
int analog5 = 4;

// LED pins
int ledPin1 = 3;
int ledPin2 = 5;
int ledPin3 = 6;
int ledPin4 = 9;
int ledPin5 = 10;

// Readings from the sensor
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
int sensorValue4 = 0;
int sensorValue5 = 0;

// Was the ball hit?
int wasHit1 = 0;
int wasHit2 = 0;
int wasHit3 = 0;
int wasHit4 = 0;
int wasHit5 = 0;

// We need to save 5 readings so we can check
// if there are at least  zeros in a row
int readings1[5];
int total1 = 0;
int average1 = 0;
int numReadings1 = 0;
int totalReadings1 = 5;
int index1 = 0;

int readings2[5];
int total2 = 0;
int average2 = 0;
int numReadings2 = 0;
int totalReadings2 = 5;
int index2 = 0;

int readings3[5];
int total3 = 0;
int average3 = 0;
int numReadings3 = 0;
int totalReadings3 = 5;
int index3 = 0;

int readings4[5];
int total4 = 0;
int average4 = 0;
int numReadings4 = 0;
int totalReadings4 = 5;
int index4 = 0;

int readings5[5];
int total5 = 0;
int average5 = 0;
int numReadings5 = 0;
int totalReadings5 = 5;
int index5 = 0;

void setup() {
  // start serial port at 9600 bps:
  Serial.begin(9600);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);

  // Set up our readings array
  for (int i=0; i< totalReadings1; i++) {
    readings1[i] = 0;
  }
  for (int i=0; i< totalReadings2; i++) {
    readings2[i] = 0;
  }
  for (int i=0; i< totalReadings3; i++) {
    readings3[i] = 0;
  }
  for (int i=0; i< totalReadings4; i++) {
    readings4[i] = 0;
  }
  for (int i=0; i< totalReadings5; i++) {     readings5[i] = 0;   } }   void loop() {     // Read analog inputs:   sensorValue1 = analogRead(analog1);   Serial.print(sensorValue1, DEC);   Serial.print(",");   sensorValue2 = analogRead(analog2);   Serial.print(sensorValue2, DEC);   Serial.print(",");   sensorValue3 = analogRead(analog3);   Serial.print(sensorValue3, DEC);   Serial.print(",");   sensorValue4 = analogRead(analog4);   Serial.print(sensorValue4, DEC);   Serial.print(",");   sensorValue5 = analogRead(analog5);   Serial.print(sensorValue5, DEC);   Serial.println();      // If the sensor value is greater than our threshold   // and the ball was not previously hit, light up the LED   if (sensorValue1 >= sensorThreshold && wasHit1 == 0) {
    wasHit1 = 1;

    // Fade the LED
    for(int fadeValue = 255; fadeValue >= 0; fadeValue -=5) {
      // sets the value (range from 0 to 255):
      analogWrite(ledPin1, fadeValue);
      // wait for 30 milliseconds to see the dimming effect
      delay(30);
    }
  }

  if (wasHit1 == 1) {
    //analogWrite(ledPin1, 0);
    // Let's grab the sensor readings and average them
    if (numReadings1 < totalReadings1) {
      readings1[index1] = sensorValue1;

      for (int i=0; i< 1) {         wasHit1 = 0;       }       average1 = 0;       numReadings1 = 0;       total1 = 0;     }     }     if (sensorValue2 >= sensorThreshold && wasHit2 == 0) {
    wasHit2 = 1;

    // Fade the LED
    for(int fadeValue = 255; fadeValue >= 0; fadeValue -=5) {
      // sets the value (range from 0 to 255):
      analogWrite(ledPin2, fadeValue);
      // wait for 30 milliseconds to see the dimming effect
      delay(30);
    }
  }

  if (wasHit2 == 1) {
    // Let's grab the sensor readings and average them
    if (numReadings2 < totalReadings2) {
      readings2[index2] = sensorValue2;

      for (int i=0; i< 1) {         wasHit2 = 0;       }       average2 = 0;       numReadings2 = 0;       total2 = 0;     }     }     if (sensorValue3 >= sensorThreshold && wasHit3 == 0) {
    wasHit3 = 1;

    // Fade the LED
    for(int fadeValue = 255; fadeValue >= 0; fadeValue -=5) {
      // sets the value (range from 0 to 255):
      analogWrite(ledPin3, fadeValue);
      // wait for 30 milliseconds to see the dimming effect
      delay(30);
    }
  }

  if (wasHit3 == 1) {
    //analogWrite(ledPin1, 0);
    // Let's grab the sensor readings and average them
    if (numReadings3 < totalReadings3) {
      readings3[index3] = sensorValue3;

      for (int i=0; i< 1) {         wasHit3 = 0;       }       average3 = 0;       numReadings3 = 0;       total3 = 0;     }     }       if (sensorValue4 >= sensorThreshold && wasHit4 == 0) {
    wasHit4 = 1;

    // Fade the LED
    for(int fadeValue = 255; fadeValue >= 0; fadeValue -=5) {
      // sets the value (range from 0 to 255):
      analogWrite(ledPin4, fadeValue);
      // wait for 30 milliseconds to see the dimming effect
      delay(30);
    }
  }

  if (wasHit4 == 1) {
    //analogWrite(ledPin1, 0);
    // Let's grab the sensor readings and average them
    if (numReadings4 < totalReadings4) {
      readings4[index4] = sensorValue4;

      for (int i=0; i< 1) {         wasHit4 = 0;       }       average4 = 0;       numReadings4 = 0;       total4 = 0;     }     }       if (sensorValue5 >= sensorThreshold && wasHit5 == 0) {
    wasHit5 = 1;

    // Fade the LED
    for(int fadeValue = 255; fadeValue >= 0; fadeValue -=5) {
      // sets the value (range from 0 to 255):
      analogWrite(ledPin5, fadeValue);
      // wait for 30 milliseconds to see the dimming effect
      delay(30);
    }
  }

  if (wasHit5 == 1) {
    //analogWrite(ledPin1, 0);
    // Let's grab the sensor readings and average them
    if (numReadings5 < totalReadings5) {
      readings5[index5] = sensorValue5;

      for (int i=0; i< 1) {
        wasHit5 = 0;
      }
      average5 = 0;
      numReadings5 = 0;
      total5 = 0;
    }

  }

  delay(10);
}

------------------------
PROCESSING CODE
------------------------
import processing.serial.*;     // import the Processing serial library
Serial myPort;                  // The serial port
import ddf.minim.*;

Minim minim;
AudioSample [] tone = new AudioSample[2];

void setup() {
  size(10,10);
  // List all the available serial ports
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  Arduino module, so I open Serial.list()[0].
  // Change the 0 to the appropriate number of the serial port
  // that your microcontroller is attached to.
  myPort = new Serial(this, Serial.list()[0], 9600);
  // read bytes into a buffer until you get a linefeed (ASCII 10):
  myPort.bufferUntil('\n');

  minim = new Minim(this);
  //tone[0] = minim.loadSample("31189_acclivity_Triangle1.wav");
  //tone[1] = minim.loadSample("45102_Matias.Reccius_crashB.wav");
  //tone[2] = minim.loadSample("31189_acclivity_Triangle1.wav");
  //tone[3] = minim.loadSample("45102_Matias.Reccius_crashB.wav");
  //tone[4] = minim.loadSample("31189_acclivity_Triangle1.wav");
}

void draw() {
  background(255);
}

void serialEvent(Serial myPort) {
  // read the serial buffer:

  String myString = myPort.readStringUntil('\n');
  if (myString != null) {

    println(myString);
  }
  myString = trim(myString);

  // split the string at the commas
  // and convert the sections into integers:
  int sensors[] = int(split(myString, ','));

  // print out the values you got:
  for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {     print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");   }   // add a linefeed after all the sensor values are printed:   println();       if(sensors[0] > 4) {
    //tone[0].trigger();
  }
  if(sensors[1] > 4) {
    //tone[1].trigger();
  }
  if(sensors[2] > 4) {
    //tone[2].trigger();
  }
  if(sensors[3] > 4) {
    //tone[3].trigger();
  }
  if(sensors[4] > 4) {
    //tone[4].trigger();
  }
}

Comment Pages

There are 3 Comments to "Human Wind Chime – Final Piece"

Write a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Refresh Your Mind