LEGO MINDSTORMS Robots Manual page 60

Unofficial guide
Table of Contents

Advertisement

The transitions from 0 to 1 and from 1 to 0 are called edges. A transition from 0 to 1 is a
rising edge, while a transition from 1 to 0 is a falling edge.
The SENSOR_EDGE configuration counts all edges, rising or falling. SENSOR_PULSE is a
little more selective—it counts rising edges only.
The following example plays a sound after every fourth press on the touch sensor. It begins by configuring input 1 to count touch presses with the SENSOR_PULSE configuration. Then it enters
an endless loop, repeatedly testing the value of input 1. If it is 4, a sound is played, and the count for input 1 is reset.
task main() {
SetSensor(SENSOR_1, SENSOR_PULSE);
while(true) {
if (SENSOR_1 == 4) {
PlaySound(SOUND_DOWN);
ClearSensor(SENSOR_1);
}
}
}
The SetSensor() command actually configures an input's type and mode at the same time. The input type describes the electrical characteristics of the attached sensor, while the mode
determines how the sensor values are interpreted. If you need finer control over the inputs than you can get from SetSensor(), use the SetSensorType() and SetSensorMode()
commands:
SetSensorType(expression sensor, const type)
This command specifies the type of sensor attached to the given input. Input types are listed in Table 4-2. This command specifies how the RCX should treat an input, electrically speaking. The
SENSOR_TYPE_LIGHT type, for example, supplies power to the sensor. (I described this back in Chapter 3.)
Page 63

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

Subscribe to Our Youtube Channel

Table of Contents