NXC  Version 1.2.1 r5
 All Data Structures Files Functions Variables Groups Pages
Sensor types and modes

Constants that are used for defining sensor types and modes. More...

Modules

 Combined sensor type and mode constants
 Use the combined sensor type and mode constants to configure both the sensor mode and type in a single function call.
 
 NBC sensor mode constants
 Use sensor mode constants to configure an input port for the desired sensor mode.
 
 NBC sensor type constants
 Use sensor type constants to configure an input port for a specific type of sensor.
 
 Sensor mode constants
 Use sensor mode constants to configure an input port for the desired sensor mode.
 
 Sensor type constants
 Use sensor type constants to configure an input port for a specific type of sensor.
 

Detailed Description

Constants that are used for defining sensor types and modes.

The sensor ports on the NXT are capable of interfacing to a variety of different sensors. It is up to the program to tell the NXT what kind of sensor is attached to each port. Calling SetSensorType configures a sensor's type. There are 16 sensor types, each corresponding to a specific type of LEGO RCX or NXT sensor. Two of these types are for NXT I2C digital sensors, either 9V powered or unpowered, and a third is used to configure port S4 as a high-speed RS-485 serial port. A seventeenth type (SENSOR_TYPE_CUSTOM) is for use with custom analog sensors. And an eighteenth type (SENSOR_TYPE_NONE) is used to indicate that no sensor has been configured, effectively turning off the specified port.

In general, a program should configure the type to match the actual sensor. If a sensor port is configured as the wrong type, the NXT may not be able to read it accurately. Use either the Sensor type constants or the NBC sensor type constants.

The NXT allows a sensor to be configured in different modes. The sensor mode determines how a sensor's raw value is processed. Some modes only make sense for certain types of sensors, for example SENSOR_MODE_ROTATION is useful only with rotation sensors. Call SetSensorMode to set the sensor mode. The possible modes are shown below. Use either the Sensor mode constants or the NBC sensor mode constants.

When using the NXT, it is common to set both the type and mode at the same time. The SetSensor function makes this process a little easier by providing a single function to call and a set of standard type/mode combinations. Use the Combined sensor type and mode constants.

The NXT provides a boolean conversion for all sensors - not just touch sensors. This boolean conversion is normally based on preset thresholds for the raw value. A "low" value (less than 460) is a boolean value of 1. A high value (greater than 562) is a boolean value of 0. This conversion can be modified: a slope value between 0 and 31 may be added to a sensor's mode when calling SetSensorMode. If the sensor's value changes more than the slope value during a certain time (3ms), then the sensor's boolean state will change. This allows the boolean state to reflect rapid changes in the raw value. A rapid increase will result in a boolean value of 0, a rapid decrease is a boolean value of 1.

Even when a sensor is configured for some other mode (i.e. SENSOR_MODE_PERCENT), the boolean conversion will still be carried out.