Concept Flow - noTone() to stop sound
Start
Call tone(pin, freq)
Sound plays on pin
Call noTone(pin)
Sound stops on pin
End
The program starts, plays a tone on a pin, then stops the sound by calling noTone on the same pin.
tone(8, 1000); // Play 1000Hz tone on pin 8 delay(1000); // Wait 1 second noTone(8); // Stop sound on pin 8
| Step | Action | Pin | Frequency | Sound State | Output |
|---|---|---|---|---|---|
| 1 | Call tone() | 8 | 1000 | Playing | Tone starts on pin 8 at 1000Hz |
| 2 | delay(1000) | - | - | Playing | Sound continues for 1 second |
| 3 | Call noTone() | 8 | - | Stopped | Sound stops on pin 8 |
| 4 | End | - | - | Stopped | No sound playing |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| pin 8 sound state | Stopped | Playing | Playing | Stopped | Stopped |
tone(pin, frequency) starts sound on a pin noTone(pin) stops sound on that pin Use noTone() to end a tone early Without noTone(), sound plays indefinitely Works on Arduino digital pins
noTone(pin) do?noTone(pin) is designed to stop any sound that is currently playing on the given pin.tone(pin, frequency) which starts a sound, noTone(pin) stops it.noTone(pin); where pin is the pin number.noTone8(); uses invalid function name. noTone(pin=8); uses invalid named parameter syntax. noTone(); omits the pin number. noTone(8); is correct.tone(9, 1000); delay(500); noTone(9); delay(500);
tone(9, 1000); starts a 1000 Hz sound on pin 9. The delay(500); pauses the program for 500 milliseconds while the tone plays.noTone(9); stops the sound on pin 9. The following delay(500); pauses for another 500 ms with no sound.tone(7, 500); noTone(); delay(1000);
noTone() requires the pin number to specify which pin to stop sound on. Here, it is called without any argument, which is incorrect.tone(7, 500); is valid, and delay(1000); is allowed after noTone(). The error is only the missing pin argument in noTone().tone(6, 440, 2000); plays tone for 2 seconds automatically, so calling noTone(6); immediately after stops it early, which is unnecessary.tone(6, 440);
delay(2000);
noTone(6); plays tone on pin 6 at 440 Hz, waits 2 seconds, then stops the tone with noTone(6);. This correctly plays sound for 2 seconds then stops.noTone(6);
tone(6, 440);
delay(2000); stops tone before playing it. tone(6, 440);
noTone(6);
delay(2000); stops tone immediately after starting, so no sound lasts. tone(6, 440, 2000);
noTone(6); stops tone immediately after starting with duration, which is redundant.Pass the test and this pattern moves unknown