int buzzerPin = 7;
int buttonPin = 4;
int buttonState = 0;
char c;
void setup( ) {
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop( ) {
buttonState = digitalRead(buttonPin);
if ((buttonState == HIGH) && (Serial.available()>0)){
c = Serial.read();
if (c = 'h'){
tone(buzzerPin,2000);
}
if (c = 'm'){
tone(buzzerPin,1200);
}
if (c = 'l'){
tone(buzzerPin,500);
}
}
if (buttonState == LOW){
noTone(buzzerPin);
}
}
= != ==
what do you mean?
eQuist:
what do you mean?
if (c = 'h') {
changing "if (c = 'h') {" to "if (c == 'h') {" doesn't work either
Then perhaps the buzzer isn't connected correctly, or you aren't receiving an 'h' or it's the wrong type of buzzer.
Try a simple program that just writes a tone to the buzzer directly.
Steve
thank you, seems like there was a problem with my buzzer