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

165


                           .StartTask 2
                      .EndOfTask
                      .BeginOfTask 1
                           .While 0, 0, 2, 0, 0
                               .PlayTone   392, 10
                               .PlayTone 523, 10
                               .PlayTone 659, 10
                               .PlayTone 784, 20
                               .PlayTone 659, 10
                               .PlayTone 784, 20
                               .Wait 2, 80
                               .Wait 2, 80
                           .EndWhile
                      .EndOfTask
                      .BeginOfTas  k 2
                           .On "02"
                           .While 0, 0, 2, 0, 0
                               .SetFwd "02"
                               .Wait 2, 50
                               .SetRwd "02"
                               .Wait 2, 50
                           .EndWhile
                      .EndOfTa  sk
                      Pause 5
                      .CloseComm
                  End With
              End Sub

          Tasks 1 and 2 both use While and  EndW hile to loop forever. Task 1 plays a song over and over, while task 2 runs the
          outputs in forward and reverse.

          Tips

          You've already seen a lot of the functionality of Spiri t.ocx exposed in NQC. Although the syntax in Visual Basic is different,
          the basic functions are the sam e. LEGO's official Tech nical Reference Document (see the ''Online Resources") does a good job
          describing the syntax  of Spirit. ocx commands; I won't attempt to duplicate that work. Instead, this section contains down-to-
          earth information on using Spirit.ocx.

          Retrieving Input and Timer Values

          Although the Technical Referenc e Document makes it clear how to reset timer values and how to configure the RCX's inputs,
          you may be left wonder ing how  to retrieve the value of an input or timer. The answer is a versatile function called Poll.
          Poll can return  many val ues from the RCX, including input values (in several different forms), timer values, variable values,
                              C
          the curr ent status  of the R X's outputs, an d the last value received  over the IR port.
   171   172   173   174   175   176   177   178   179   180   181