Sensors
Colour sensor
color_sensor (Technic Color Sensor).
Modes (also as class attributes):
Constant |
Mode # |
Purpose |
|---|---|---|
|
0 |
Detected colour index ( |
|
1 |
Reflected-light intensity (0..100 %) |
|
2 |
Ambient-light intensity (0..100 %) |
|
3 |
On-board LED output (write-only) |
|
5 |
Raw RGB channels + intensity |
|
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 |
|---|---|---|
|
0 |
Detected colour index |
|
1 |
Distance (cm) |
|
3 |
Reflected-light (%) |
|
4 |
Ambient-light (%) |
|
5 |
On-board LED colour (write-only) |
|
6 |
Raw RGB channels |
|
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