Page 162 - The Unofficial Guide to Lego Mindstorms Robots
P. 162
151
Programming the Remote Control
The remote control doesn't really have to do much. It responds to its sensors by sending commands to Minerva. The joystick
control triggers the two touch sensors; the remote responds to these by telling Minerva to move forward or spin. The slider
control is used to move Minerva's arm up or down.
One final feature is a ''heartbeat"—a special message that the remote periodically sends to Minerva. If Minerva doesn't hear
this message, it knows it has lost contact with the remote.
The remote uses three different tasks to get everything done. One task monitors the touch sensors, one task monitors the light
se nsor, and the third task sends the heartbeat signal. Here is the code for those tasks:
#define FORWARD_MESSAGE 16
#define SPIN_MESSAGE 17
#define STOP_MESSAGE 18
#define GRAB_MESSAGE 19
#define RELEASE_MESSAGE 20
#define HEARTBEAT_MESSAGE 21
#define HEARTBEAT_TIME 20
task main() {
SetSensor(SENSOR_1, SENSOR_LIGHT);
SetSensor(SENSOR_2, SENSOR_TOUCH);
SetSensor(SENSOR_3, SENSOR_TOUCH);