Musical Level

Submitted by lwang on Wed, 03/06/2013 - 01:50

Description:

The goal of my project was to create a level that signified an even plane based on the distance from the photocells. When both ends of the cardboard are equidistant from the photocell, the music would turn on. The only issue I had was that the values of the photocells differed in sensitivity too much, and it was too difficult for me to find the correct interval to make the music sound.

Material:

Arduino board

chopsticks

tape

cardboard

scissors

wires

 

Code:

 

/* Theremin
 * --------
 *
 *
 * Created 24 October 2006
 * copyleft 2006 Tod E. Kurt <tod@todbot.com
 * http://todbot.com/
 */
 
int potPin = 0;    // select the input pin for the potentiometer
int potPin2 = 2;
int speakerPin = 7;
                      
int val = 0;
int val2 = 0;
int valThreshold = 50;
 
void setup() {
  pinMode(speakerPin, OUTPUT); 
  Serial.begin(9600);                                
  Serial.println("ready");
}
 
void loop() {
  digitalWrite(speakerPin, 0);
  
  val = analogRead(potPin);    // read value from the sensor
  val = val*2;                 // process the value a little
  //val = val/2;                 // process the value a little
  val2 = analogRead(potPin2);
  val2 = val2/12;
  
  int valDiff = abs(val - val2); // get the difference between the two values
 
  Serial.println("Values:");  // prints out value from pin
  Serial.println(val);  // prints out value from pin
  Serial.println(val2);  // prints out value from pin
 
 
  if(valDiff <= valThreshold){
    for( int i=0; i<500; i++ ) {  // play it for 50 cycles
      digitalWrite(speakerPin, HIGH);
      delayMicroseconds(val);
      digitalWrite(speakerPin, LOW);
      delayMicroseconds(val);
    }
  }
}
 
photo-3.JPG
0
Your rating: None
Drupal theme by Kiwi Themes.