Tone()

From Microduino Wiki
Jump to: navigation, search

tone()

  • Description

Produce a specific frequency square wave on a pin(50% duty ratio). And the time of duration can be set, or the waveform will be produce all the time until the noTone() function is called. This pin can be connected with the piezoelectric buzzer or other horn to play the sound.

At one time, only one sound can be produced. If a pin is already playing music, the call of the tone() will have no effect. If music is played in the same pin, it will adjust the frequency automatically.

If use unction tone() , it will interfere with the PWM of pin3 and pin11(except Mega).

Note:If you want different tones to be produced on multiple pins, you should call function noTone() to the next pin before calling function tone() to this pin.

  • Syntax

tone(pin, frequency) 
tone(pin, frequency, duration)
  • Parameters

pin:The pin to produce the sound

frequency: The frequency of the sound to be produced, in Hz, and unsigned int

duration:The time the sound lasts for, in milliseconds(optional),, and unsigned long

  • Return

No [Return to Arduino Syntax Manual]