Page 214 - The Unofficial Guide to Lego Mindstorms Robots
P. 214

203


           Sound (rom/sound.h and direct-sound.h)

          You can play one of the RCX's built-in ''system" sounds with the following function:

          void sound_system(unsigned nr)
          This function plays one of the system sounds of the RCX. The nr parameter describes the sound; it can be any of the values
          shown in Table 10-1.

          Table 10-1. sound_system() Sound Numbers

          Sound Number     Description

          0                Short  beep

          1                Two medium  beeps

          2                Descending  arpeggio

          3                Ascending  arpeggio

          4                Long  low note

                                                             a
          5                  Quick ascending arpeggio (same as 3 but f ster)
          F urthermore, you can play any sound you want using this function:

          void ds_play(unsigned char ∗sample, unsigned length)

          This function plays the sound data described by sample, using length bytes of data. The sample data should be 1 bit, 8
          k Hz data.



                        Unfortunately, neither sound _system() nor ds_play() works in the March 30, 1999 build of legOS 0.1.7

                        .

          Other Goodies

          legOS has a grab-bag of other intere sting features. In this section, these functions are organized by the header file in which
              r
             a
          they  e defined.

          In stdlib.h

          legOS supports a simple random numb er generator with the following two functions:

          long int random(void)
          This function returns a pseudorandom  number.

          void srandom(unsigned int seed)
          Use this function to provide a new seed for th e pseudorandom number generator.
   209   210   211   212   213   214   215   216   217   218   219