playTone

Play tone on piezo speaker using digital pin

Description

example

playTone(a,pin,frequency,duration) plays a tone on a piezo speaker attached to the digital pin on Arduino® hardware at the specified pin and frequency for the specified duration.

Examples

collapse all

Play a tone connected to digital pin 5 on the Arduino hardware for 10 seconds at 2400Hz.

a = arduino();
playTone(a,'D5',2400,10);

Input Arguments

collapse all

Arduino hardware connection created using arduino, specified as an object.

Digital pin number on the physical hardware, specified as a character vector.

Frequency of tone to be played, specified as a number between the frequency range 0 and 32767Hz.

Duration of tone to be played specified as a number, which represents the number of seconds. Valid values are between 0 and 60.

Limitations

This function is not supported on the Arduino MKR1000, the Arduino MKR1010, Arduino MKR Zero and the Arduino Due boards .

See Also

Introduced in R2014b