speak
#define NOTE_C5 100
#define NOTE_C3 350
int o=0;
int led=9;
int speaker=8;
int y=0;
int q=1;
void setup(){
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(speaker,OUTPUT);
}
void loop(){
int readvalue = analogRead(A0);
float x = readvalue * (255.0/1023.0);
int z=x;
if(z==0){
digitalWrite(led,LOW);
noTone(8);
y=0;
}
else if(z>0 && z<255){
y=NOTE_C5+z;
analogWrite(led,z);
tone(8, y,4);
}
else{
digitalWrite(led,HIGH);
speakerr();
delay(500);
digitalWrite(led,LOW);
delay(500);
y=0;
}
}
void speakerr(){
for(int k=0;k<800;k++){
tone(8,NOTE_C3,4);
}
}