Advanced I/O
1. tone()
1.1. Description
Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to noTone(). The pin can be connected to a piezo buzzer or other speaker to play tones.
1.2. Syntax
tone(pin, frequency)
tone(pin, frequency, duration)
1.3. Parameters
pin
: the pin on which to generate the tone
frequency
: the frequency of the tone in hertz - unsigned int
duration
: the duration of the tone in milliseconds (optional) - unsigned long
1.4. Returns
Nothing
1.5. Notes and Warnings
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.
2. noTone()
2.1. Description
Stops the generation of a square wave triggered by tone()
. Has no effect if no tone is being generated.
2.2. Syntax
noTone(pin)
2.3. Parameters
pin
: the pin on which to stop generating the tone
2.4. Returns
Nothing
2.5. Notes and Warnings
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.