Assignment: Input / Output Coincidence Lab Assignment
Collaborators:
* 1 Light Emitting Diode (LED)
* 1 220 OHM resistor
* Wires
* Arduino board
* Breadboard
* 1 photocell
* 1 piezo
/* Musical Jewelry Box
* --------
*
*
* Created 10/09/08
* Modified by Xiaomeng Zhong
*
*/
int potPin = 0;
int speakerPin = 7;
int ledPin = 9;
int val = 0;
void setup() {
pinMode(speakerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
beginSerial(9600);
Serial.println("ready");
}
void loop() {
//Speaker and LED: OFF
digitalWrite(speakerPin, LOW);
digitalWrite(ledPin, LOW);
val = analogRead(potPin); // read value from the sensor
val = val*2; // process the value a little
//val = val/2; // process the value a little
Serial.println(val);
if (val>40) //when the box is opened, turn on LED and play sounds
{
digitalWrite(ledPin, HIGH);
for( int i=0; i<500; i++ ) { // play it for 50 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
}
}
}