Friday, November 3, 2017

Project 1: DJ Sound Box

PROJECT DESCRIPTION:
Our task was to create a musical art piece that integrates three different sensing modes. It must also have at least two LEDs---one to indicate whether the device is on or off and another one that changes in response to user interaction. The device should also generate sound in response to either the environment or user interaction. There should also be a button that turns the music on/off.

INDIVIDUAL PROJECT CONTRIBUTION:
Richard and I collaborated on a majority of the coding and debugging process. For example, on the one hand, I coded the function that allowed the Arduino to convert the analog signal from the photoresistor to a brightness value for the LEDs. On the other hand, Richard finalized logic statements  within my function that would play 8-bit tones while the LED was illuminated. I also used the serial monitor to calibrate the extrema of our photoresistor values to the brightness of the LEDs. Richard made it clear to me that he had trouble calibrating the light values, so I taught him the process, helped him analyze the values; and by the end of the project, he had calibrated most of the light values. We also troubleshooted a majority of the hardware together. For instance, I established a methodology for wiring the lasers and the LEDs, while Richard soldered the necessary components together. While Richard acquired most of the electrical components for this project---e.g alligator clips, lasers, and speakers---we shared the burden of ensuring that these pieces made it into the final piece. For instance, approximately 48 hours before our project was due, we discovered that Richard had left his soldering iron in the ENGR 6 classroom. At this point, we still had a majority of our components to solder together, including the lasers and speakers. However, I was able to obtain a different soldering iron the next day, allowing us to complete the necessary connections and by extension our project as a whole. Moreover, approximately 5 hours before the deadline, I discovered and undid a major hardware problem---involving one of our speakers and buttons---that resolved a major roadblock for the upload of our code to the Arduino, thereby allowing my teammate Richard to amend that portion of the hardware and assemble the breadboard-Arduino wire nest within of our cardboard package. This DJ music box is therefore demonstrative of a collaborative effort that was only made possible by our joint skill set and problem-solving knowledge.

PROJECT CODE:
// Project 4 Mason
// This program facilitates the use of our DJ sound box. It uses photo resistors as inputs, lasers, LED's, and speakers as outputs.
int BUTTON_1 = 4;// First button on pin 4 is a mute button for the music
int BUTTON_2 = 3;// Second button on pin 3 controls Imperial March music
int buttonState_1 = LOW;// This variable stores the on/off state of the mute button
int buttonState_2 = LOW;// This variable stores the on/off state of the music button
int SPEAKER_1 = 9;// First Speaker on pin 9
int SPEAKER_2 = 8;
int SPEAKER_3 = 7;
int SPEAKER_4 = 6;
int SPEAKER_5 = 5;// This speaker plays Imperial March
const int RLED = 10;// Two Red LEDs connected in parallel on pin 10 (PWM)
const int GLED = 11;
const int BLED = 0;
const int GLED_RGB = 1;// Green LED on pin 1
const int RLED_RGB = 2;// Red LED on pin 2
const int LASER_1 = 12;// Two cheap lasers connected in parallel on pin 12
const int LASER_2 = 13;
const int LIGHT = A0;// Light Sensor (aka photoresistor) on analog pin 0
const int LIGHT_2 = A1;
const int LIGHT_3 = A4;
const int LIGHT_4 = A2;
const int MIN_LIGHT = 10; //MINIMUM expected light value for first photoresistor
const int MAX_LIGHT = 240;//MAXIMUM Expected Light value for first photoresistor
const int MINLIGHT2 = 20;
const int MAXLIGHT2 = 650;
const int MINLIGHT3 = 10;
const int MAXLIGHT3 = 240;
const int MINLIGHT4 = 10;
const int MAXLIGHT4 = 240;
int val = 0; //variable to hold the analog reading for the light value of photoresistor
int val_2 = 0;
int val_3 = 0;
int val_4 = 0;
void setup()
{
Serial.begin(9600); // Set the bit rate for serial communication to 9600
pinMode(RLED, OUTPUT); //Set LED pin as output
pinMode(GLED, OUTPUT);
pinMode(BLED, OUTPUT);
pinMode(GLED_RGB, OUTPUT);
pinMode(RLED_RGB, OUTPUT);
pinMode(LASER_1,OUTPUT); //Set laser pin as output
pinMode(LASER_2,OUTPUT);
pinMode(LIGHT, INPUT); //Set Photoresistor as input
pinMode(LIGHT_2,INPUT);
pinMode(LIGHT_3,INPUT);
pinMode(LIGHT_4,INPUT);
pinMode(BUTTON_1, INPUT); //Set first button as input
pinMode(BUTTON_2, INPUT);
pinMode(SPEAKER_1, OUTPUT); //Set speaker as output
pinMode(SPEAKER_2, OUTPUT);
pinMode(SPEAKER_3, OUTPUT);
pinMode(SPEAKER_4, OUTPUT);
pinMode(SPEAKER_5, OUTPUT);
}
void loop()
{
buttonState1 = digitalRead(BUTTON1);
buttonState2 = digitalRead(BUTTON2);
// The following three variables control: (a) the previous state of the music button,
// (b) the current state of the music button, and (c) the on/off state of its
// connected speaker
/*boolean lastButton = LOW;
boolean currentButton = LOW;
boolean SPEAKER5On = false;
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
SPEAKER_5_On = !SPEAKER_5_On;
}
lastButton = currentButton;
if (SPEAKER5On)
}
else
{
boolean SPEAKER_5_On = false;
}*/
if (buttonState_1 == HIGH) //if mute button has been pressed...
{
noTone(SPEAKER_5); //turn off the music speaker
}
if (buttonState_2 == HIGH)
{
// play the Music 
tone(9,146.83,400);//D 
delay(400); 
tone(9,146.83,400);//D
delay(400); 
tone(9,146.83,250);//D 
delay(250); 
tone(9,174.61,250);//F
delay(250); 
tone(9,196.00,350);//G 
delay(400); 
tone(9,146.83,350);//D
delay(400); 
tone(9,146.83,200);//D 
delay(250); 
tone(9,146.83,200);//D
delay(250); 
tone(9,130.81,400);//C 
delay(450); 
tone(9,130.81,400);//C
delay(450); 
tone(9,146.83,400);//D 
delay(450); 
tone(9,146.83,400);//D
delay(450); 
tone(9,146.83,400);//D 
delay(450); 
tone(9,174.61,400);//F
delay(300); 
tone(9,196.00,400);//G 
delay(450); 
tone(9,146.83,400);//D
delay(450); 
tone(9,146.83,400);//D 
delay(450); 
tone(9,146.83,400);//D
delay(450); 
tone(9,130.81,400);//C 
delay(300); 
tone(9,130.81,400);//C
delay(300); 
tone(9,130.81,400);//C 
delay(450); 
tone(9,174.61,400);//F
delay(450); 
tone(9,146.83,400);//D 
delay(450); 
tone(9,220.00,400);//A
delay(450); 
tone(9,174.61,400);//D 
delay(450); 
tone(9,146.83,400);//D
delay(450); 
tone(9,207.65,400);//GSHARP 
delay(450);
}
{
val = analogRead(LIGHT); //Read the light sensor
val = map(val, MINLIGHT, MAXLIGHT, 255,0 );//Map the light reading
val = constrain(val, 0, 255); //Constrain light value
analogWrite(RLED, val); //Control the LED
Serial.println(val);
delay(200);
if(val > 150) { tone(SPEAKER_1, val+200,200); //digitalWrite(RGB_LED.HIGH) delay(10); }
}
//////////////////////////////////////////////////////////////////////////////////////////
{
val2 = analogRead(LIGHT2); //Read the light sensor
val2 = map(val2, MINLIGHT2, MAXLIGHT2, 255,0 );//Map the light reading
val2 = constrain(val2, 0, 255); //Constrain light value
analogWrite(GLED, val_2); //Control the LED
Serial.println(val_2);
delay(200);
if(val_2 > 150) { tone(SPEAKER_2, 2000,100); delay(100); tone(SPEAKER_2, 1500,100); delay(10); tone(SPEAKER_2, 1000,100); delay(150);tone(SPEAKER_2, 2000,100); delay(10); tone(SPEAKER_2, 1500,200);delay(100); tone(SPEAKER_2, 2000,200); delay(10); }
}
//////////////////////////////////////////////////////////////////////////////////////////
{
val3 = analogRead(LIGHT3); //Read the light sensor
val3 = map(val3, MINLIGHT3, MAXLIGHT3, 255,0 );//Map the light reading
val3 = constrain(val3, 0, 255); //Constrain light value
analogWrite(LASER1, val3); //Control the LED
//digitalWrite(GLED, HIGH);
Serial.println(val_3);
delay(200);
if(val_3 > 140) { tone(SPEAKER_3, val_3-600,200); delay(10); }
}
//////////////////////////////////////////////////////////////////////////////////////////
{
val4 = analogRead(LIGHT4); //Read the light sensor
val4 = map(val3, MINLIGHT4, MAXLIGHT4, 255,0 );//Map the light reading
val4 = constrain(val4, 0, 255); //Constrain light value
analogWrite(LASER2, val4); //Control the LED
//digitalWrite(GLED, HIGH);
Serial.println(val_4);
delay(200);
if(val_4 > 140) { tone(SPEAKER_4, val_4+1000,200); delay(10); }
}
if(val<150)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED_RGB, LOW);
digitalWrite(BLED, HIGH);
}
}

No comments:

Post a Comment