LEGO MINDSTORMS Robots Manual page 124

Unofficial guide
Table of Contents

Advertisement

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.
Having read an input value, you are now ready to retrieve it using one of the following words:
SENSOR_VALUE (index--value)
This word returns the value of the given input. The range of the returned value is determined by the mode of the input.
SENSOR_RAW (index--value)
Use this word to obtain the raw value of the input described by index. The raw value will always be in the range from 0 to 1023.
SENSOR_BOOL (index--value)
This word returns the current value of the given input as a Forth-style boolean.
For example, to read the value of the sensor on input 3, you would do this:
: 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.
Finally, 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 index on the stack.
There 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:
Page 133

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the MINDSTORMS Robots and is the answer not in the manual?

Questions and answers

Table of Contents