Project 1
Comment: At first Mathew and I didn't know what we wanted to do for the first project. After bouncing around a few ideas we settled on a a dj box that does shoots light/lasers depending on the CDS analog value. We cut holes in the cups then wedge the CDS sensor then attached the lasers and led to the arduino. What Mathew and I had the most trouble was the wiring since we had 4 CDS, 4 lasers, and 4 led. We also ran out of wires so we had to strip and solder a lot of wires together, which got really messy rally fast. The final project didn't work as intended, the connections of the wires were really bad, so some of the lights didn't work.
//Project 4 Mason
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 MIN_LIGHT_2 = 20;
const int MAX_LIGHT_2 = 650;
const int MIN_LIGHT_3 = 10;
const int MAX_LIGHT_3 = 240;
const int MIN_LIGHT_4 = 10;
const int MAX_LIGHT_4 = 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()
//#define C0 16.35
//#define Db0 17.32
//#define D0 18.35
//#define Eb0 19.45
//#define E0 20.60
//#define F0 21.83
//#define Gb0 23.12
//#define G0 24.50
//#define Ab0 25.96
//#define LA0 27.50
//
//
//#define C1 32.70
//#define Db1 34.65
//#define D1 36.71
//#define Eb1 38.89
//#define E1 41.20
//#define F1 43.65
//#define Gb1 46.25
//#define G1 49.00
//#define Ab1 51.91
//#define LA1 55.00
//#define Bb1 58.27
//
//#define C2 65.41
//#define Db2 69.30
//#define D2 73.42
//#define Eb2 77.78
//#define E2 82.41
//#define F2 87.31
//#define Gb2 92.50
//#define G2 98.00
//#define Ab2 103.83
//#define LA2 110.00
//#define Bb2 116.54
//#define B2 123.47
//#define C3 130.81
//#define Db3 138.59
//#define D3 146.83
//#define Eb3 155.56
//#define E3 164.81
//#define F3 174.61
//#define Gb3 185.00
//#define G3 196.00
//#define Ab3 207.65
//#define LA3 220.00
//#define Bb3 233.08
//#define B3 246.94
//#define C4 261.63
//#define Db4 277.18
//#define D4 293.66
//#define Eb4 311.13
//#define E4 329.63
//#define F4 349.23
//#define Gb4 369.99
//#define G4 392.00
//#define Ab4 415.30
//#define LA4 440.00
//#define Bb4 466.16
//#define B4 493.88
//#define C5 523.25
//#define Db5 554.37
//#define D5 587.33
//#define Eb5 622.25
//#define E5 659.26
//#define F5 698.46
//#define Gb5 739.99
//#define G5 783.99
//#define Ab5 830.61
//#define LA5 880.00
//#define Bb5 932.33
//#define B5 987.77
//#define C6 1046.50
//#define Db6 1108.73
//#define D6 1174.66
//#define Eb6 1244.51
//#define E6 1318.51
//#define F6 1396.91
//#define Gb6 1479.98
//#define G6 1567.98
//#define Ab6 1661.22
//#define LA6 1760.00
//#define Bb6 1864.66
//#define B6 1975.53
//#define C7 293.00
//#define Db7 2217.46
//#define D7 2349.32
//#define Eb7 2489.02
//#define E7 2637.02
//#define F7 2793.83
//#define Gb7 2959.96
//#define G7 3135.96
//#define Ab7 3322.44
//#define LA7 3520.01
//#define Bb7 3729.31
//#define B7 3951.07
//#define C8 4186.01
//#define Db8 4434.92
//#define D8 4698.64
//#define Eb8 4978.03
//// DURATION OF THE NOTES
//#define BPM 120 // you can change this value changing all the others
//#define H 2*Q //half 2/4
//#define Q 60000/BPM //quarter 1/4
//#define E Q/2 //eighth 1/8
//#define S Q/4 // sixteenth 1/16
//#define W 4*Q // whole 4/4
{
buttonState_1 = digitalRead(BUTTON_1);
buttonState_2 = digitalRead(BUTTON_2);
// 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 SPEAKER_5_On = false;
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
SPEAKER_5_On = !SPEAKER_5_On;
}
lastButton = currentButton;
if (SPEAKER_5_On)
{
}
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, MIN_LIGHT, MAX_LIGHT, 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);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
{
val_2 = analogRead(LIGHT_2); //Read the light sensor
val_2 = map(val_2, MIN_LIGHT_2, MAX_LIGHT_2, 255,0 );//Map the light reading
val_2 = constrain(val_2, 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);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
{
val_3 = analogRead(LIGHT_3); //Read the light sensor
val_3 = map(val_3, MIN_LIGHT_3, MAX_LIGHT_3, 255,0 );//Map the light reading
val_3 = constrain(val_3, 0, 255); //Constrain light value
analogWrite(LASER_1, val_3); //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);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
{
val_4 = analogRead(LIGHT_4); //Read the light sensor
val_4 = map(val_3, MIN_LIGHT_4, MAX_LIGHT_4, 255,0 );//Map the light reading
val_4 = constrain(val_4, 0, 255); //Constrain light value
analogWrite(LASER_2, val_4); //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);
}
}

//Project 4 Mason
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 MIN_LIGHT_2 = 20;
const int MAX_LIGHT_2 = 650;
const int MIN_LIGHT_3 = 10;
const int MAX_LIGHT_3 = 240;
const int MIN_LIGHT_4 = 10;
const int MAX_LIGHT_4 = 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()
//#define C0 16.35
//#define Db0 17.32
//#define D0 18.35
//#define Eb0 19.45
//#define E0 20.60
//#define F0 21.83
//#define Gb0 23.12
//#define G0 24.50
//#define Ab0 25.96
//#define LA0 27.50
//
//
//#define C1 32.70
//#define Db1 34.65
//#define D1 36.71
//#define Eb1 38.89
//#define E1 41.20
//#define F1 43.65
//#define Gb1 46.25
//#define G1 49.00
//#define Ab1 51.91
//#define LA1 55.00
//#define Bb1 58.27
//
//#define C2 65.41
//#define Db2 69.30
//#define D2 73.42
//#define Eb2 77.78
//#define E2 82.41
//#define F2 87.31
//#define Gb2 92.50
//#define G2 98.00
//#define Ab2 103.83
//#define LA2 110.00
//#define Bb2 116.54
//#define B2 123.47
//#define C3 130.81
//#define Db3 138.59
//#define D3 146.83
//#define Eb3 155.56
//#define E3 164.81
//#define F3 174.61
//#define Gb3 185.00
//#define G3 196.00
//#define Ab3 207.65
//#define LA3 220.00
//#define Bb3 233.08
//#define B3 246.94
//#define C4 261.63
//#define Db4 277.18
//#define D4 293.66
//#define Eb4 311.13
//#define E4 329.63
//#define F4 349.23
//#define Gb4 369.99
//#define G4 392.00
//#define Ab4 415.30
//#define LA4 440.00
//#define Bb4 466.16
//#define B4 493.88
//#define C5 523.25
//#define Db5 554.37
//#define D5 587.33
//#define Eb5 622.25
//#define E5 659.26
//#define F5 698.46
//#define Gb5 739.99
//#define G5 783.99
//#define Ab5 830.61
//#define LA5 880.00
//#define Bb5 932.33
//#define B5 987.77
//#define C6 1046.50
//#define Db6 1108.73
//#define D6 1174.66
//#define Eb6 1244.51
//#define E6 1318.51
//#define F6 1396.91
//#define Gb6 1479.98
//#define G6 1567.98
//#define Ab6 1661.22
//#define LA6 1760.00
//#define Bb6 1864.66
//#define B6 1975.53
//#define C7 293.00
//#define Db7 2217.46
//#define D7 2349.32
//#define Eb7 2489.02
//#define E7 2637.02
//#define F7 2793.83
//#define Gb7 2959.96
//#define G7 3135.96
//#define Ab7 3322.44
//#define LA7 3520.01
//#define Bb7 3729.31
//#define B7 3951.07
//#define C8 4186.01
//#define Db8 4434.92
//#define D8 4698.64
//#define Eb8 4978.03
//// DURATION OF THE NOTES
//#define BPM 120 // you can change this value changing all the others
//#define H 2*Q //half 2/4
//#define Q 60000/BPM //quarter 1/4
//#define E Q/2 //eighth 1/8
//#define S Q/4 // sixteenth 1/16
//#define W 4*Q // whole 4/4
{
buttonState_1 = digitalRead(BUTTON_1);
buttonState_2 = digitalRead(BUTTON_2);
// 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 SPEAKER_5_On = false;
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
SPEAKER_5_On = !SPEAKER_5_On;
}
lastButton = currentButton;
if (SPEAKER_5_On)
{
}
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, MIN_LIGHT, MAX_LIGHT, 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);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
{
val_2 = analogRead(LIGHT_2); //Read the light sensor
val_2 = map(val_2, MIN_LIGHT_2, MAX_LIGHT_2, 255,0 );//Map the light reading
val_2 = constrain(val_2, 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);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
{
val_3 = analogRead(LIGHT_3); //Read the light sensor
val_3 = map(val_3, MIN_LIGHT_3, MAX_LIGHT_3, 255,0 );//Map the light reading
val_3 = constrain(val_3, 0, 255); //Constrain light value
analogWrite(LASER_1, val_3); //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);
}
}
//////////////////////////////////////////////////////////////////////////////////////////
{
val_4 = analogRead(LIGHT_4); //Read the light sensor
val_4 = map(val_3, MIN_LIGHT_4, MAX_LIGHT_4, 255,0 );//Map the light reading
val_4 = constrain(val_4, 0, 255); //Constrain light value
analogWrite(LASER_2, val_4); //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);
}
}
Comments
Post a Comment