Page 74 - The Unofficial Guide to Lego Mindstorms Robots
P. 74
63
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 SE NSOR_TYPE_LIGHT type, for example, supplies
power to the sensor. (I described this back in Chapter 3.)
Table 4-2. Input Type Constants
T ype Constant Sensor Type
S ENSOR_TYPE_TOUCH Touch sensor
SENSOR_TYPE_TEMPERATURE Temperature sensor
SENSOR_TYPE_LIGHT Light sensor (powered)
SENSOR_TYPE_ROTATION Rotation sensor (powered)
SetSensorMode(expression sensor, const mode)
U se this command to set the mode of the given input. While the SetSensorType() comm and is used to specify the
electrical characteristics of the input, the SetSensorMode() command specifies how the inpu t value should be processed.
T he modes are listed in Table 4-3.
T able 4-3. Input Mode Constants
M ode Constant Description
S ENSOR _MODE_RAW Raw sensor value from 0 to 1023
SENSOR_MODE_BOOL Either 1 or 0
SENSOR_MODE _EDGE Counts transitions from 1 to 0 and vice versa
SENSOR_MODE_PULSE Counts transitions from 1 to 0
SENSOR_MODE_PER CENT Percent from 0 to 100
S ENSOR_MODE_CELSIUS Celsius temperature
S ENSOR_MODE_FAHRENHEIT Fahrenheit temperature
SENSOR_MODE_ROTATION Shaft angle, 16 counts per full revolution
Internally, input values initially have a raw value from 0 to 1023. Raw values are conver ted to the input values that your
p rogram sees by a process that depends on the input mode. Three of the modes count events: SENSOR_MODE_EDGE,
SENSOR_MODE_P ULSE, and SENSOR_MODE_ROTATION. The other modes perform a mathematical scaling operation on
the raw input value.
For example, if the input mode is SENSOR_MODE_PERCENT, the RCX converts the raw value into a percent according to the
equation: