User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Flute Powered By Light

Submitted by sarah_vanwart on Wed, 10/08/2008 - 22:55

Assignment: Input / Output Coincidence Lab Assignment

Collaborators:

Collaborators: Ljuba Miljkovic

Description

The purpose of this lab was to:

  1. Experiment with manipulating Piezo Speakers.
  2. Continue developing an understanding of circuitry.
  3. Create an object in which input and output are coincident.

Components Used

  • Arduino board
  • Red, green, and blue Light Emitting Diodes
  • 3 220 Ohm Resistors (red, red, brown, gold)
  • 4 10K resistor (brown,black, yellow)
  • USB Cable (for power)
  • Wires
  • 1 Piezo Speaker
  • 4 Photocells
  • Soldering iron and solder
  • 1 Diffusing Filter
  • Rubber Bands

Flute Powered By Light

Ljuba and I decided to make a flute that is powered by light (instead of wind). By pressing the four different photocells in various combinations, different notes are played (an entire octave has been coded), and different LED lights are illuminated.

Circuit Photos

Arduino Code

We created a circuit with four input sensors (photocells). By covering up the sensors, or "pressing the keys," the Piezo speaker can be manipulated to play a scale. LED lights concurrently change colors as well, and are diffused using an opaque cylinder in the shape of a flute (sort of).

int speakerPin = 7;     //Speaker Mapping

int photocell_C = 0;    // Photocell Mapped to C
int photocell_D = 1;    // Photocell Mapped to D
int photocell_E = 2;    // Photocell Mapped to E
int photocell_F = 3;    // Photocell Mapped to F

int greenPin = 9;       // select the pin for the LED 9
int redPin   = 10;      // select the pin for the LED 10
int bluePin  = 11;      // select the pin for the LED 11

//threshold for turning notes on and off.  Though we experimented with various
//percentage change calculations, the photocells are so sensitive and varied
//that this hardcoding strategy works best in this case:
int C_MIN = 200;
int D_MIN = 400;
int E_MIN = 10;
int F_MIN = 150;


//http://www.home.agilent.com/agilent/editorial.jspx?cc=US&lc=eng&ckey=431980&nid=-536902257.793368.02&id=431980
int C = 956;
int D = 851;
int E = 758;
int F = 716;
int G = 638;
int A = 568;
int B = 506;
int C_HIGH = 478; //238;


void setup() {
  pinMode(speakerPin, OUTPUT); 
  beginSerial(9600);
  Serial.println("ready");

}

void loop() {
  
  Serial.print("C: ");  Serial.print(analogRead(photocell_C));
  Serial.print("   D: ");  Serial.print(analogRead(photocell_D)); 
  Serial.print("   E: ");  Serial.print(analogRead(photocell_E)); 
  Serial.print("   F: ");  Serial.println(analogRead(photocell_F)); 
  
  if(analogRead(photocell_C) < C_MIN && analogRead(photocell_D) < D_MIN)
  {
     playLight(bluePin);
     playNote(G);
  }
  else if(analogRead(photocell_C) < C_MIN && analogRead(photocell_E) < E_MIN)
  {
     playLight(greenPin);
     playNote(A);     
  }
  else if(analogRead(photocell_C) < C_MIN && analogRead(photocell_F) < F_MIN)
  {     
     playLight(redPin);
     playNote(B);     
  }
  else if(analogRead(photocell_D) < D_MIN && analogRead(photocell_E) < E_MIN)
  {     
     playLight(bluePin);
     playNote(C_HIGH);
  }
  else if(analogRead(photocell_C) < C_MIN)
  {     
     playLight(greenPin);
     playNote(C);
  }
  else if(analogRead(photocell_D) < D_MIN)
  {     
     playLight(redPin);
     playNote(D);
  }
  else if(analogRead(photocell_E) < E_MIN)
  {     
     playLight(bluePin);
     playNote(E);
  }
  else if(analogRead(photocell_F) < F_MIN)
  {     
     playLight(greenPin);
     playNote(F);
  }
  else
  {
    analogWrite(greenPin, 0);
    analogWrite(redPin, 0);
    analogWrite(bluePin, 0);
  }
}

void playLight(int thePin)
{
  analogWrite(greenPin, 0);
  analogWrite(redPin, 0);
  analogWrite(bluePin, 0);
  analogWrite(thePin, 255);
}

void playNote(int theNote)
{
   for( int i=0; i<200; i++ ) 
   {
      digitalWrite(speakerPin, HIGH);
      delayMicroseconds(theNote);
      digitalWrite(speakerPin, LOW);
      delayMicroseconds(theNote);
    }
}

Flute Photographs