Stops the generation of a square wave triggered by tone(). Has no
effect if no tone is being generated.
Use the following function to stop a tone:
noTone(pin)
The function admits the following parameter:
pin: the Arduino pin on which to stop generating the tone.
The function returns nothing.
Generate a square wave on pin D0 for a second and then stop it repetitively.
#define BUZZER_PIN D0 // Example pin
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
tone(BUZZER_PIN, 1000); // 1 kHz tone
delay(1000);
noTone(BUZZER_PIN); // Stop the tone
delay(1000);
}
If you want to play different pitches on multiple pins, you need to call
noTone() on one pin before calling tone() on the next pin.