The RCX display is a powerful tool for receiving feedback from different
programs. Often times, however, it is necessary to monitor more than
one variable at the same time. One solution to this problem is to
use a program similar to the one above.
The code above is designed to give feedback on two touch sensors.
The first step is to zero all relevant containers.
Remember, since containers are also global, old values from earlier
tests could still be stored, so zeroing them is essential. Next,
a task split is used to monitor the two touch sensors separately.
Each branch of the split waits for its touch sensor to be pressed,
adds either 1 or 100 to the red container, and then waits for the
sensor to be released. Thus the total clicks of touch sensor 1 will
be displayed in first two digits of the display, and the total clicks
of touch sensor 2 will be displayed in the last two digits of the
display. This code can be adapted to show any kind of sensor value,
including light or rotation. If the variables are in seperate containers
in the program, just multiply one container by a constant so that
it will display in the hundreds or thousands place on the display.
Then just add the two contatiners together in a thrid container
and display that value.
Two RCX's can be programmed to communicate with each other using
the mail function. Mail represents the passing of integer values
between separate RCX's using the IR port. In this example, the same
code is used for both the receiver and the sender, so that you may
interchange the roles of two RCX's without having to re-program
The top half of the first split is the receiving algorithm. Each
RCX will wait to receive mail from the other. Once this happens,
the integer value received will be placed into the red container.
The value is then displayed and the RCX beeps a corresponding number
of times. The RCX then waits for mail again.
The bottom half of the first split is the sending algorithm. The
user can enter in a mail value to send by pressing touch sensor
1 the desired number of times. For example, if number 3 was to be
sent, touch sensor 1 would be pressed 3 times. Once this value is
programmed, pressing touch sensor 2 will send the mail out. In general,
mail is a useful way for RCX's to pass information to one another.
It can be used to trigger responses, send positions, or pass container
The two-button remote control is a very versatile program for controlling
Lego robots. It uses a series of touch sensor forks to determine which
behavior you want to trigger. Since the forks are between a set of
jumps, the program loops infinitely, and the behavior of the robot
will change every time a different touch sensor is hit.
In this program, the two-button remote is setup to control a car
with motors on ports A and C. When only touch sensor 1 is pressed,
motor A spins forward and motor A spins backward. This will turn
the car left or right. When only touch sensor 2 is pressed, the
motors are reversed and the car will spin the opposite direction.
If both touch sensors are held, the car moves forward. When no touch
sensors are held, the car does not move. Remember, each branch of
the fork can control something different. It does not only work
for a car. The touch sensors can trigger music, events, even mail
to other robots. The possibilities are endless.