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

70


                  PlayTone(311, SIXTH);
                  PlayTone(277, 3   ∗BEAT);
                  Wait(4∗SIX  TH + 3∗BEAT + HALF);
                  PlayTone(277, HALF);
                  PlayTone(3  11, HALF);
                  PlayTone(370, GRACE);
                  PlayTone(3  30, HALF);
                  PlayTone(3  11, HALF); Wait (2∗HALF);
                  PlayTone(2  77, HALF);
                  PlayTone(3  30, HALF);
                  PlayTone(2  20, HALF);
                  PlayTone(22  0, 2∗BEAT);
                  Wait(GRACE + 5   ∗HALF + 2∗BEAT + HALF);
                  PlayTone(24  7, HALF);
                  PlayTone(277, HALF);
                  PlayTone(33  0, GRACE);
                  PlayTone(311, HALF);
                  PlayTone(277, HALF); Wait (2∗HALF);
                  PlayTone(247, HALF);
                  PlayTone(311, HALF)    ;
                  PlayTone(208, HALF);
                                    ∗
                  PlayTone(208, 2 BEAT);
                  Wai t(GRACE + 5∗HALF + 2∗BEAT + HALF);
              }

          IR Communication

          Y our robot can send and receive data over its IR port. In NQC, three commands handle sending and receiving data:

          SendMessage(expression m)
          This command sends the give n byte of data out the IR port.

          Message()
          Use this command to return the last byte of data received on the IR port.

          C learMessage()
          This command clears the incoming message. You may want to do this after responding to an incoming message, to avoid
          responding more than once.

          Th e Display

          Although you can't control the d isplay directly in NQC, you can configure it to some degree:

          SelectDisplay(expression v)
          This command tells the RCX to show the data source represen ted by v on its display. The legal values for v are shown in
          Table 4-6.  You can achieve the same results by pressing the  View button on the front of the RCX to show the state of the
          inputs or outputs, but the Se lectDisplay() command allow you to do this as part of a program.
   76   77   78   79   80   81   82   83   84   85   86