This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

playTone

Play tone on piezo speaker using digital pin

Syntax

playTone(a,pin,frequency,duration)

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, and the Arduino Due boards .

See Also

Introduced in R2014b