If Statement: Tone Frequency
Closed this issue · 0 comments
kkaila777 commented
Hello. I am trying to figure out what the function would be for stopping the buzzer for a frequency over 330. There are some errors in my code; I need some help with my integers and the syntax for the argument. Also need clarification on the purpose of a function for tone frequency. Thanks!
int buzzer = 12;
int frequency = 330;
void setup() {
// put your setup code here, to run once:
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (buzzer > frequency){
analogWrite (buzzer, frequency);
delay (1000);
}
else { analogWrite (buzzer, LOW);
}
tone(buzzer,440); //A
delay(1000);
;
tone(buzzer,370); //F#
delay(1000);
tone(buzzer,330); //E
delay(500);
tone(buzzer,370); //F#
delay(200);
tone(buzzer,330); //E
delay(400);
tone(buzzer,294); //D
delay(500);
tone(buzzer,330); //E
delay(500);
}