const int buttonPin=2;
const int ledPin=13;
const int speakerPin=11;
int buttonState=0;
const int C1=262;
const int Dn=294;
const int En=330;
const int Fn=349;
const int Gn=392;
const int An=440;
const int Bn=494;
const int C2=523;
const int phototransistor = A0;
int Val = 0;
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin,INPUT);
pinMode(speakerPin, OUTPUT);
pinMode(phototransistor,INPUT);
}
void loop() {
Val = analogRead(phototransistor); //Read the value of the A2 pin and assign that value to Val
if (Val<500) {
Serial.println (Val);
tone(speakerPin, C1);
delay(250);
noTone(speakerPin);
delay(50);
tone(speakerPin, Dn);
delay(250);
noTone(speakerPin);
delay(50);
tone(speakerPin, En);
delay(250);
noTone(speakerPin);
delay(50);
tone(speakerPin, Fn);
delay(250);
noTone(speakerPin);
delay(50);
tone(speakerPin, Gn);
delay(250);
noTone(speakerPin);
delay(50);
tone(speakerPin, An);
delay(250);
noTone(speakerPin);
delay(50);
tone(speakerPin, Bn);
delay(250);
noTone(speakerPin);
delay(50);
tone(speakerPin, C2);
delay(550);
noTone(speakerPin);
delay(100);
}
else
{
noTone(speakerPin);
digitalWrite (ledPin, LOW);
}
}