ROBOLAB examples

Theseย examples (PDF) demonstrate the use of various features in ROBOLAB.

NXT multiple events
NXT multiple events
  • Multiple events can be setup in the same code to track different variables. All event structures must have the same event landing. This means that if 3 events are setup and only one triggers, the code will have to determine which one of the 3 changed so it can perform the appropriate action.In this example, two push events are used to control the motion of a car. After setting up both events, monitoring is started and the code is forced into an infinite loop. This is done to prevent the code from reaching the event landing block prematurely. If the red event (touch sensor 1) is triggered, the code will take the upper path in the event fork and stop motor A. If the red event was not triggered, then by default, the blue event must have been triggered and the code will take the bottom the path of the fork. Three or more events can be checked by increasing the number of event forks.

Sending and receiving mail

  • 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 them.
  • 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 values.

NXT-3 button sensor remote

  • Like its smaller cousin, the three-button remote control is a great way to define unique behaviors for your robot. The advantage to the three-button control is that there are now 8 possible behavior combinations, compared to just 4 on the 2-button remote. In addition to forward, left and right motion on our two motor car, it is now possible to move in reverse, and even control a third motor. With so many combinations, it is possible that you don?t need them all. In a case like that, simply wire the fork branch you don?t want to control straight into the merge fork block. If the program travels along that branch, it will simply jump back to the beginning again.

NXT Control the display

NXT Control the display
  • This example 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 separate 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 containers together in a third container and display that value.

2 button touch sensor remote (2)

  • 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.

Other examples included…

3-button remote
  • 3 button touch sensor remote
  • A rotation sensor remote
  • Advanced proportional control
  • Controlling the display
  • Data logging from computer
  • Data logging the light sensor
  • Direct control from ROBOLAB- RCX code
  • direct control of the RCX from ROBOLAB-RCX code
  • Direct mode
  • Drive black line
  • Echo location
  • Hello world
  • Line follower events
  • Line follower wait for the dark
  • Lurch
  • Lurch subroutine
  • Lurch subroutine
  • Playing the D major scale
  • Proportional control
  • Random
  • Reprogramming another RCX
  • Setting up multiple events
  • Show LASM
  • Touch sensor fork
  • Using the light sensor to measure
  • Wait for push


The following two tabs change content below.


The Tufts Center for Engineering Education and Outreach (CEEO) in Boston, Massachusetts, is dedicated to improving engineering education in the classroom, from Kindergarten to college. The Center houses faculty, staff, and graduate students from engineering disciplines and the education department.

Latest posts by CEEO (see all)