Making sounds

I am trying to make some sounds:

task main()

bPlaySounds = true;
nVolume = 4;

while(time1[T1] < 180000)

    if (time1[T1] > 165000)
        setTouchLEDColor(port12, colorRed);
        setTouchLEDBlinkTime(port12, 0, 0); // no blink
        setTouchLEDColor(port2, colorRed);
        setTouchLEDBlinkTime(port2, 0, 0); // no blink

but for no avail.

Please anyone can help?



Hi Karim,

The sounds only seem to work if your code waits for the sound to complete before moving ahead with other commands. Adding a sleep command after each sound should take care of it.

However, you probably don’t want to suspend everything else, like driving controls, just to wait for the sound. As an alternative you can launch the sound in a separate thread.

The following code launches a MatchTimer thread from the main program when a button on the controller is pressed. The match timer makes sounds when it’s time to switch drivers, when the match is about to end, and once it has ended. This routine makes it a lot easier to time your practice matches.

// this thread makes sounds to indicate the time remaining in the match
task MatchTimer()
int i;

bPlaySounds = true;
nVolume = 4;

playSound(soundTollBooth);  //starting sound

sleep(25000); // wait 25 seconds

//time to switch drivers,
for(i = 0; i < 10; i++) // 10 warnings at 1 second intervals
// Drivers must have switched by now
sleep(5000); // 20 sec warning

sleep(10000); // 10 secs left
for(i = 0; i < 10; i++) // countdown

playSound(soundTada);  // end of match sound


task main()

if(getJoystickValue(BtnFUp)) // start sequence


Let me know if it works for you.


I tried this but is not working:

task MatchTimer()
bPlaySounds = true;
nVolume = 4;

task main()
int threshold = 10;
static int leftSpeed = 0;
static int rightSpeed = 0;

// idle loop used for remote start
while(vexRT[BtnRUp] == 0)

if(getJoystickValue(BtnRUp)) // start sequence




The sound worked for me. Thanks

The MatchTimer code that I posted previously stopped working when we upgraded the RobotC firmware to to 1.09. Only about 1/3 of the sounds are actually audible now. The sounds that play seem to be random. That makes the MatchTimer useless because the driver can’t rely on the sounds to know how much time is left. This had been working flawlessly.

kaoua - Sorry I didn’t respond to your post, didn’t see that you had posted a reply until today. Glad that you got the sound working. Have you upgraded your firmware and did the sound still work afterwards?

jpearman - thanks for the tip about the CODE tag, I’ll try that next time. However, the driver can’t always see the LCD, and wouldn’t want to focus on it when driving.

I used this piece of code and sound:

As well as:

if (vexRT[BtnRUp] == 1)

in the task main()

task MatchTimer()
bPlaySounds = true;
//nVolume = 1;

It is working for me. I will try your code and see

It worked for me. At least the sounds you tried, I have the latest robotc 4.08 and vex iq frimware 1.09. Try to add brealpoints in your task(MatchTimer), you will hear the sound.

We’re working on making the sound functionality in the VEX IQ better at the moment. The issue is that the VEX IQ hardware does not support playing a specific frequency, but rather two different methods of playing sounds. Some of the built in commands in ROBOTC that other platforms have used do not work on the VEX IQ and have been accidentally left “enabled”. We’re fixing this issue for the next build. In the mean time, here’s the two ways to get a sound to play on the VEX IQ.

Method #1: Built In Sound “Effects”
You can use the “playSound(nSoundID)” function to have a sound effect play for one “loop”. Sound effect names are…


So an example to play the ‘Firmware Update Complete’ sound would be

playSound(soundTada); //This will cause the sound effect to play once.

Since some sound effects are shorter, you can also use the…
playRepetitiveSound(TSounds sound, const int durationIn10MsecTicks)
to play them continuously. So the following line of code:

playRepetitiveSound(soundTada, 100); 

would loop that sound effect for 1 second (or a little over, in case the last instance of the sound might go over depending on length).

Method #2: Playing a “Note”
ROBOTC has a (somewhat difficult to use) command to play a specific note from the VEX IQ. You’re able to specify both a note and an octave for the sound chip in the VEX IQ to play. Notes are enumerated as such.

0  - C
1  - C#
2  - D
3  - D#
4  - E
5  - F
6  - F#
7  - G
8  - G#
9  - A
10 - A#
11 - B

To play the command you’ll need to create a variable to store the Note + Octave using the following formula:

TMusicalNotes nNoteToPlay = (nOctaveValue << 4) + nNoteInOctave;

Then to play the specific note, you can use the command
playNote(const TMusicalNotes nNote, const int durationIn10MsecTicks)

Example Usage:

TMusicalNotes nNoteToPlay = (3 << 4) + 5; //3rd Octave, Note 'E'
PlayNote(nNoteToPlay,  30); //Play the note for 300ms

We’re working on making the PlayNote command easier to use, but this will let you get started today. If you have any questions, let us know!

Is there an update the playNote command? We can’t find documentation in the help.