Reference for Wiring version 0024+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Name

tone()

Examples
void setup() {
  tone(0, 400, 200); // generates a 400Hz tone in output pin 0 with 200ms of duration
}

void loop() {

}

void setup() {
  tone(0, 400, -1); // generates a 400Hz tone in output pin 0 with infinite duration
}

void loop() {

}
Description The tone() generates a tone of a determined frequency in hertz on a specific pin with a specified duration. The tone command uses timer2 to generate the tone accurately. Use a negative number in duration for infinite duration.
Syntax
tone(pin, frequency, duration)
Parameters
pin int the PWM output pin number in which the pulse will be generated. It can only be on 29, 30 or 31 PWM output pins
frequency int: the frequency for the pulse in Hertz
duration int: the tone duration in milliseconds or a negative number for infinite duration
Returns None
Usage Application
Related noTone()
Updated on January 26, 2010 11:24:28pm PST

Creative Commons License