Sensors

Colour sensor

color_sensor (Technic Color Sensor).

Modes (also as class attributes):

Constant

Mode #

Purpose

MODE_COLOR

0

Detected colour index (lpf2.color)

MODE_REFLT

1

Reflected-light intensity (0..100 %)

MODE_AMBI

2

Ambient-light intensity (0..100 %)

MODE_LIGHT

3

On-board LED output (write-only)

MODE_RGB

5

Raw RGB channels + intensity

MODE_HSV

6

HSV (H 0..360, S 0..100, V 0..360)

The wrapper polls modes 0/1/5/6 through an internal combo, so all readings are available without switching modes:

dev = port.device()   # color_sensor
dev.getColorIdx()
dev.getReflectivity()
r, g, b, i = dev.getRGB()
h, s, v = dev.getHSV()

Drive the on-board LED segments (0..100 % each):

dev.setLight(80, 0, 0)     # segment 1 = 80 %

Distance sensor

distance_sensor (Technic Distance Sensor, time-of-flight).

dev = port.device()   # distance_sensor
cm = dev.getDistance()
dev.setLight(50, 50, 50, 50)   # four segments

Colour + distance (legacy)

color_distance_sensor (WeDo / Boost).

Constant

Mode #

Purpose

MODE_COLOR

0

Detected colour index

MODE_DIST

1

Distance (cm)

MODE_REFLT

3

Reflected-light (%)

MODE_AMBI

4

Ambient-light (%)

MODE_LED

5

On-board LED colour (write-only)

MODE_RGB

6

Raw RGB channels

MODE_IR

7

LEGO PF IR transmit (write-only)

dev = port.device()   # color_distance_sensor
dev.getColorIdx()
dev.getDistance()
dev.getReflectedLight()
dev.getAmbientLight()
dev.getRgb()
dev.setLedColor(color.BLUE)
dev.setIrTx(0x123)

Built-in inertial sensors

accelerometer and gyroscope wrap the on-board inertial measurement chip as LPF2-typed devices. Their raw axes (getX/Y/Z) are useful when you want to avoid the fusion in hub.imu (e.g. to feed a custom filter).

ax = hub.accelerometer.getX()   # mG
gz = hub.gyro.getZ()            # dps

For fused pitch/roll/yaw use hub.imu — see IMU.