Main Content

playTone

Play tone on piezo speaker using digital pin

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.

Description

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.

example

playTone(a,pin) plays a tone on a piezo speaker attached to the digital pin on Arduino hardware.

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

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 Due, MKR1000, MKR1010, MKR Zero, Nano33IoT, Nano33BLE and ESP32 boards.

Version History

Introduced in R2014b

See Also

Go to top of page