Main Content

playTone

Play tones from speaker on EV3 brick

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

Description

example

playTone(myev3) plays a 500 Hz tone for 1 second at volume level 10 on the speaker that is located on the EV3 brick.

example

playTone(myev3,freq,duration,volume) plays a tone with a specific frequency, duration, and volume.

Examples

collapse all

Play a tone, and then a short melody.

Create a connection to the EV3 brick called myev3.

myev3 = legoev3;

Play a tone that uses the default values.

playTone(myev3)

Play a series of tones. Specify the frequencies, duration, and volume of each tone.

playTone(myev3,412.0,0.5,10)
pause(0.5)
playTone(myev3,550.0,0.75,50)
pause(0.75)
playTone(myev3,925.0,0.25,10)
pause(0.25)
playTone(myev3,734.2,0.80,50)

The pauses give each tone time to finish before the next tone starts.

Input Arguments

collapse all

Connection to EV3 brick, specified as a string that represents the object created using legoev3.

Example: myev3

Data Types: char

The frequency of the tone in Hertz, specified as a double.

Example: 500

Data Types: double

The duration of the tone in seconds, specified as a double.

Example: 1

Data Types: double

The relative volume of the tone, specified as a double.

Example: 50

Data Types: double

Version History

Introduced in R2015a