As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Tuesday, May 19, 2015

Lamp reacting to sound

For our project, we wanted to have a way to have out lamp change brightness with the surrounding sound. We were able to find a code similar to what we wanted where each light bulb would turn on when the microphone sensor picked up the sound. Here is what the code that we used! 

// Arduino pin numbers 
//const int DO_pin = 2;
 const int AO_pin = 0; 

int sound; 

int led1 = 8; 
int led2 = 9;
 int led3 = 10; 
int led4 = 11; 
int led5 = 12; 

void setup() 
{ //pinMode(DO_pin, INPUT); 
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT); 
 pinMode(led3, OUTPUT); 
pinMode(led4, OUTPUT); 
pinMode(led5, OUTPUT); 

 Serial.begin(9600); } 

 void loop() { 
if (sound > 36) 
{ digitalWrite(led1, HIGH); } 
if (sound < 36) { digitalWrite(led1, LOW); } 
if (sound > 40) { digitalWrite(led2, HIGH); }
 if (sound < 40) { digitalWrite(led2, LOW); } 
if (sound > 45) { digitalWrite(led3, HIGH); } 
if (sound < 45) { digitalWrite(led3, LOW); }
 if (sound > 50) { digitalWrite(led4, HIGH); }
 if (sound < 50) { digitalWrite(led4, LOW); }
 if (sound > 55) { digitalWrite(led5, HIGH); }
 if (sound < 55) { digitalWrite(led5, LOW); }

 sound = analogRead(AO_pin)* 0.1;
 //Serial.print(digitalRead(DO_pin)); 
Serial.print("-"); Serial.println(analogRead(AO_pin)); }

No comments:

Post a Comment