Sensor types and modes
SetInputMode configures an input port with a type (which electrical
interface and which sensor) and a mode (how the firmware converts the
reading into the scaled value). The high-level sensor types pick these for
you. With RawSensor and the low-level API you choose them yourself.
Types
SensorType | Code | Sensor | High-level type |
|---|---|---|---|
NoSensor | 0x00 | Nothing | — |
Switch | 0x01 | Touch sensor (NXT or RCX) | Touch |
Temperature | 0x02 | RCX temperature | RawSensor |
Reflection | 0x03 | RCX light | RawSensor |
Angle | 0x04 | RCX rotation | RawSensor |
LightActive | 0x05 | NXT light, floodlight on | Light<_, _, Reflected> |
LightInactive | 0x06 | NXT light, floodlight off | Light<_, _, Ambient> |
SoundDb | 0x07 | NXT sound, dB | Sound<_, _, Db> |
SoundDba | 0x08 | NXT sound, dBA | Sound<_, _, Dba> |
Custom | 0x09 | Custom analog | RawSensor |
LowSpeed | 0x0A | I²C, no 9 V | I2cBus, I2cDevice |
LowSpeed9V | 0x0B | I²C with 9 V supply | Ultrasonic, I2cBus |
HighSpeed | 0x0C | RS-485 (port 4) | — |
ColorFull | 0x0D | NXT 2.0 colour, detection | Color<_, _, Detect> |
ColorRed | 0x0E | Colour sensor, red lamp | Color<_, _, Lamp<Red>> |
ColorGreen | 0x0F | Colour sensor, green lamp | Color<_, _, Lamp<Green>> |
ColorBlue | 0x10 | Colour sensor, blue lamp | Color<_, _, Lamp<Blue>> |
ColorNone | 0x11 | Colour sensor, lamp off | Color<_, _, Ambient> |
Types 0x0C and up need NXT 2.0 firmware (1.28 or newer).
Modes
SensorMode | Code | scaled value |
|---|---|---|
Raw | 0x00 | Raw A/D value, 0–1023 |
Boolean | 0x20 | 0 or 1 |
TransitionCount | 0x40 | Number of 0↔1 transitions |
PeriodCount | 0x60 | Number of full 0→1→0 periods |
PercentFullScale | 0x80 | 0–100 |
Celsius | 0xA0 | Tenths of a degree Celsius (RCX temperature) |
Fahrenheit | 0xC0 | Tenths of a degree Fahrenheit |
AngleSteps | 0xE0 | RCX rotation steps (16 per turn) |
The low five bits of the mode byte are the slope used for boolean
conversion (0 uses fixed thresholds):
use nxt_rs::protocol::{SensorMode, Slope};
let mode = SensorMode::Boolean.with_slope(Slope::new(10).unwrap());
assert_eq!(mode.to_wire(), 0x2A);
Colour numbers
In ColorFull mode, scaled holds the detected colour:
| Value | ColorName |
|---|---|
| 1 | Black |
| 2 | Blue |
| 3 | Green |
| 4 | Yellow |
| 5 | Red |
| 6 | White |
Ultrasonic sensor registers
The LEGO ultrasonic sensor is an I²C device at address 0x02:
| Register | Content |
|---|---|
0x00 | Version (8 bytes, e.g. V1.0) |
0x08 | Product ID (LEGO) |
0x10 | Sensor type (Sonar) |
0x41 | Command: 0 off, 1 single shot, 2 continuous, 3 event capture, 4 warm reset |
0x42–0x49 | Measurements 0–7 in cm (255 = no echo) |