LEGO MINDSTORMS Robots Manual page 66

Unofficial guide
Table of Contents

Advertisement

}
The preceding example shows off two features of macros. First, each macro has a parameter, power, that is used in the body of the macro. Second, the macros are split out to multiple lines by
using a backslash.
Sounds and Music
Your RCX can play various prepackaged sounds, using the following command:
PlaySound(const n)
This command plays the sound represented by n. NQC includes constant names for each available sounds, as detailed in Table 4-5.
Table 4-5. RCX System Sounds
Sound Name
Description
SOUND_CLICK
Short beep
SOUND_DOUBLE_BEEP
Two medium beeps
(table continued on next page)
(table continued from previous page)
Table 4-5. RCX System Sounds (continued)
Sound Name
Description
SOUND_DOWN
Descending arpeggio
SOUND_UP
Ascending arpeggio
SOUND_LOW_BEEP
Long low note
SOUND_FAST_UP
Quick ascending arpeggio (same as
If you'd prefer to make your own music, you can play individual notes with the PlayTone() command:
PlayTone(const frequency, const duration)
This command plays a note with the given frequency for the specified duration. The frequency is in Hz, so 440 is the pitch of the A above middle C on a piano. The duration is in hundreths of a
second. You can only specify integer values for the frequency, so don't expect the pitches to be exactly in tune. No one expects your little robot to sound like Pavorotti.
If you want to play a sequence of notes, you have to be a little tricky about it. Each time you call PlayTone(), the command returns almost immediately, with-out waiting for the sound you've
requested to finish playing. The tone you've requested is put in a queue; the system plays it while the rest of your program executes. If you call PlayTone() repeatedly, the queue will fill up.
Subsequent calls to PlayTone() will not fit on the queue and the tones you've requested will not be played. The queue is long enough to hold eight tones. If you want to play a sequence longer
than this, you should insert calls to Wait() in your program so that the queue has time to empty out as notes are played.
The following example demonstrates this technique; it plays part of Quando men vo, from Giacomo Puccini's La Bohème.
SOUND_UP
but faster)
Page 69

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the MINDSTORMS Robots and is the answer not in the manual?

Questions and answers

Table of Contents