Page 144 - The Unofficial Guide to Lego Mindstorms Robots
P. 144
133
Having read an input value, you are now ready to retrieve it using one of the following words:
SENSOR_VALUE (index--value)
T his word returns the value of the given input. The range of the returned value is determined by the mode of the input.
S ENSOR_RAW (index--value)
Use this word to obtain the raw value of the i nput described by index. The raw value will always be in the range from 0 to
1 023.
S ENSOR_BOOL (index--value)
This word returns the current value of th e given input as a Forth-style boolean.
For exam ple, to read the value of the sensor on input 3, you would do t his:
: read 2 SENSOR_READ 2 SENSOR_VALUE . ;
Strictly speaking, of course, you should really check the return code from SENSOR_READ to make sure it was successful.
F inally, the current value of an input can be reset with the following word:
SENSOR_CLEAR (index--)
Some of the input modes count values, like the edge counting, pulse counting, and rotation modes. For these modes, the current
count of an input can be reset to 0 using SENSOR_CLEAR.
RCX Timers
The RCX has 14 timers that you can use in your programs. Four of these timers count in tenth-of-a-second intervals. Each of
these timers is identified by an index, from 0 to 3. The timers count up once every tenth of a second and have values from 0 to
7FFF (hexadecimal):
TIMER_SET (value index--)
This word sets the timer described by index to the supplied value.
TIMER_GET (index--value)
This word places the current value of the timer described by in dex on the stack.
T here are also 10 timers with a hundredth-second resolution. These timers have an index from 0 to 9; they count down instead
of up and stop when they reach 0:
timer_SET (value index--)
This word sets the timer described by index to the supplied value.
timer_GET (index--value)
This word places the current value of the timer described by index on the stack.