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

132


          (table continued from previous page)

          Table 6-8. Input Type Values (continued)

          Value     Description

          3         Light sens or

          4          Rotation sensor

          SENSOR_MODE (mode index -- )
          This word sets the mode of the given input. An input's mode determines how the sensor values will be interpreted. The modes
          are shown in Table 6-9.

          Table 6-9. Input Mode Values

          Value (hex)        Description

          0                  Raw sensor value from 0 to 1023

                                       1
          20               Boo lean, either or 0

          40                 Counts transitions from 1 to 0 and vice versa (e dge counting)

          60                 Counts transitions from  1 to 0 (pulse counting)

          80               Percent  from  0  to  100

          A0               Celsius temperature

          C 0              Fahrenheit  temperature

          E 0                 Shaft angle, 16 counts per full revolution

          The following example shows how you cou ld configure input 3 for a light sensor:

              2 CONSTANT INPUT_3
                  ok
              SENSOR_INIT
                  ok
              INPUT_3 SENSOR_ACTIVE
                  ok
              3 INPUT_3 SENSOR_TYPE
                  ok
              80 INPUT_3 SENSOR_MODE
                  ok

          Reading input values

          Reading input values in pbFORTH is a two-step process. First, you need to tell pbFORTH to go and read the input values:
          SENSOR_READ (index -- code)

          This word tells pbFORTH  to read the  value of the specified input. The actual  value can  be retrieved  with  a call to
          SENSOR_GET, which is described later. A status code is placed on the stack. If code is 0, then the read was successful.
          Values other than 0 indicate that the RCX was busy and could not read the input value.
   138   139   140   141   142   143   144   145   146   147   148