Monday, December 1, 2014

Process.3

Code for project

I took this code: 
/*
This is the code to make a LED blink with the music.
You have to set the threshold so it' sensible enough to make the led blink.
 
You connect an LED to PIN13 and the Sound Sensor to Analog Pin 0
 */
 
int led = 13;
int threshold = 500; //Change This
int volume;
 
void setup() {                
  Serial.begin(9600); // For debugging
  pinMode(led, OUTPUT);     
}
 
void loop() {
  
  volume = analogRead(A0); // Reads the value from the Analog PIN A0
  /*
    //Debug mode
    Serial.println(volume);
    delay(100);
  */
  
  if(volume>=threshold){
    digitalWrite(led, HIGH); //Turn ON Led
  }  
  else{
    digitalWrite(led, LOW); // Turn OFF Led
  }
 
}




and adjusted a few things to make my new improved code for my project:

int led1= 13;
int led2= 12;
int led3= 11;

int threshold1= 700;
int threshold2= 800;
int threshold3= 900;

int volume1;
int volume2;
int volume3;

void setup(){
   Serial.begin(9600);
   pinMode(led1, OUTPUT);
   pinMode(led2, OUTPUT);
   pinMode(led3, OUTPUT);
}

void loop(){
   volume1 = analogRead(A0);
   volume2 = analogRead(A1);
   volume3 = analogRead(A2);

   if(volume1>=threshold1){
      digitalWrite(led1,HIGH);
   }
   if(volume2>=threshold2){
      digitalWrite(led2,HIGH);
   }
   if(volume3>=threshold3){
      digitalWrite(led3,HIGH);
   }

   else{
      digitalWrite(led1, LOW);
      digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
   }
}



I mostly used what I knew about working with multiple LEDs that react to sound and made each of the 3 LEDs react to a certain sound threshold. From there, I just hooked up a couple more LEDs to the same line and I have a good number of lights to start putting around the brain!


http://www.danielandrade.net/2011/04/09/arduino-sound-sensor/ 
http://arduino.cc/en/Tutorial/MultipleBlinks 

No comments:

Post a Comment