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…
soundSiren2
soundWrongWay
soundWrongWays
soundGasFillup
soundHeadlightsOn
soundHeadlightsOff
soundTollBooth
soundCarAlarm2
soundTada
soundGarageDoorClose
soundRatchet
soundAirWrench
soundSiren4
soundRatchet4
soundCarAlarm4
soundPowerOff2
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!