10 Advanced I/O
tone()
Simple square wave tone() generation is possible for up to 8 channels using Arduino standard tone() calls. Because these use the PIO to generate the waveform, they must share resources with other calls such as I2S or Servo objects.
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.
If the tone is playing on the same pin, the call will set its frequency.
tone(pin, frequency)
tone(pin, frequency, duration)
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