Play tone on piezo speaker using digital pin
playTone(a,pin,frequency,duration)
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.
a
pin
frequency
duration
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);
Arduino hardware connection created using arduino, specified as an object.
arduino
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.
0
32767
Duration of tone to be played specified as a number, which represents the number of seconds. Valid values are between 0 and 60.
60
This function is not supported on the Arduino Due boards.
You have a modified version of this example. Do you want to open this example with your edits?