Interacting with an RCX program
The LEGO RCX is a small computer that can be programmed to add behaviours to a construction.

Since native RCX programs are composed of indipendent parallel tasks, more skillful members of the WebLbas community can develop programs that can be controlled from ToonTalk at the behaviour level. This tutorial describes a sample program to demonstrate this way of interacting with the RCX.
and this file
in the same folder.

Rcx programs can be developed in a number of program and sintaxes. In the WebLabs projects we use the NQC compiler . NQC is a command line compiler, however integrated development environment (IDE) for NQC are available. This example was developed using the Bricx Command Center.
The source code (beahviours.nqc) of the RCX program contains documentation on how to develop similar programs. This source code serves as an example and a template for TTRCX downloadable programs.
The program structure is the following:

Since native RCX programs are composed of indipendent parallel tasks, more skillful members of the WebLbas community can develop programs that can be controlled from ToonTalk at the behaviour level. This tutorial describes a sample program to demonstrate this way of interacting with the RCX.
End user
- Download this ToonTalk notebook
and this file
in the same folder.
- Double click on the Behaviours.tt file to start ToonTalk (this will set the working directory to the folder containing those two files, thus simplifying the task of telling ToonTalk where the RCX program file is located).
- Set the tower port nad test that the communication between the PC and the RCX is working by giving the RCX bird the following command:
- Download the behaviours program into the RCX
- Connect a touch sensor to the port labeled 1 on the RCX.

- The flip side of the RCX picture contains the ToonTalk code to start and stop the available behaviours:
- Touch
When the touch sensor is pressed it increments a counter.; its value is displayed on the RCX LCD.
- TooMuch
When the touch counter is greater than Max_Hits, reset the counter to 0 and plays a sound.
- Log
Logs the RCX clock reading when the touch sensor is pressed. The RCX clock is reset when the program is started. The data log buffer can register up to 100 values. The data log is reset when the program is started.
- Stop program
This is a ToonTalk robot that capture that monitors when the "." key is pressed tand signal the RCX to stop the program. Start tasks signal are sent when the "space" key is pressed. Thus making the interaction with RCX compatible with the ToonTalk way of starting and stopping robots.
- Max_Hits is the ToonTalk nuber with robots on the flip side that enable the user to query and set the value of the RCX Max_Hits variable. Press the "space" key to read its value. Edit the number to modify it.
- Press the "space" key to get the current value of the "touch" counter
- Give the rcx bird the following command to upload the dat log from the RCX into ToonTalk.
RCX programmer
Rcx programs can be developed in a number of program and sintaxes. In the WebLabs projects we use the NQC compiler . NQC is a command line compiler, however integrated development environment (IDE) for NQC are available. This example was developed using the Bricx Command Center.
The source code (beahviours.nqc) of the RCX program contains documentation on how to develop similar programs. This source code serves as an example and a template for TTRCX downloadable programs.
The program structure is the following:
- Allocation of reserved variables (3 counters and 8 task flags). Do not change this section.
- Sensor setup (the RCX requires the specification of the type of the sensors plugged in any specific construction)
- Event setup: we use an event driven approach to program the RCX.
Events can be 'static' (i.e., all their settings are know at compile time) or 'parametric' (i.e., we use variables to modify event-related values, such as a threshold, at runtime).
In the behavoiurs example, pressing the touch sensor is a static event . When the counter exceed the max number of touches depends on the value of the Max_Hits variable; this is an example of a parametric event.
- User task definition:
each task monitors one or more events and defines the code to be
executed when the event(s) is/are fired. These tasks correspond to the
ToonTalk behaviours that you can "add to"/"remove from" the picture
representing the construction.
In the behaviour exampl we have three tasks: Touch, TooMuch and Log.
- UpdateEvents and Main task definition: these should not be changed.
