LEGO Mindstorms NXT Sensors
The nxt.sensor.generic module supports the sensors manufactured by LEGO.
- class nxt.sensor.generic.Touch(brick, port)
Bases:
BaseAnalogSensorLEGO Mindstorms NXT touch sensor, part number 53793.
- is_pressed()
Get sensor pressed state.
- Returns:
Trueif the sensor is pressed, elseFalse.- Return type:
- class nxt.sensor.generic.Light(brick, port, illuminated=True)
Bases:
BaseAnalogSensorLEGO Mindstorms NXT light sensor, part number 55969.
This sensor is included in the first version of the Mindstorms NXT set and in the Education NXT set. Not to be confused with the color sensor included in the NXT 2.0 set.
- Parameters:
illuminated (bool) – Initial illuminated state.
- get_lightness()
Get detected light level.
- Returns:
Detected light level between 0 and 1023.
- Return type:
- class nxt.sensor.generic.Sound(brick, port, adjusted=True)
Bases:
BaseAnalogSensorLEGO Mindstorms NXT sound sensor, part number 55963.
- Parameters:
adjusted (bool) – Initial adjusted state.
- set_adjusted(active)
Set adjusted state. When activated, the sensitivity of the sensor is adjusted to human perception.
- Parameters:
active (bool) –
Trueto activate adjustment.
- get_loudness()
Get detected sound level.
- Returns:
Detected sound level between 0 and 1023.
- Return type:
- class nxt.sensor.generic.Ultrasonic(brick, port, check_compatible=True)
Bases:
BaseDigitalSensorLEGO Mindstorms NXT ultrasonic distance sensor, part number 53792.
- class Command(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
EnumSensor command.
- OFF = 0
Turn sensor OFF.
- SINGLE_SHOT = 1
Enable single shot mode.
- CONTINUOUS_MEASUREMENT = 2
Enable continuous measurement mode (default).
- EVENT_CAPTURE = 3
Enable event capture mode, to measure whether any other sensor is in the neighbourhood.
- REQUEST_WARM_RESET = 4
Reset sensor.
- get_measurement_units()
Get measurement units.
- Returns:
String representing the measurement units, should be “10E-2m”.
- Return type:
- get_all_measurements()
Get all the measurements.
- get_measurement_no(number)
Get one of the measurements.
- get_interval()
Get measurement interval, unknown unit.
- Returns:
Content of interval measurement register.
- Return type:
- class nxt.sensor.generic.Color(brick, port)
Bases:
BaseAnalogSensorLEGO Mindstorms NXT color sensor, part number 64892.
This sensor is included in the Mindstorms NXT 2.0 set. Not to be confused with the light sensor included in the first version or in the Education set.
- class DetectedColor(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
IntEnumColor detected by the sensor.
This is an
enum.IntEnumfor backward compatibility.- BLACK = 1
Black or low intensity.
- BLUE = 2
Blue.
- GREEN = 3
Green.
- YELLOW = 4
Yellow.
- RED = 5
Red.
- WHITE = 6
White.
- set_light_color(color)
Set the light color.
- Parameters:
color (Type) – Light color, or off, must be one of the Type.COLOR_* values.
- get_light_color()
Get the light color previously set.
- Returns:
Light color, one of the Type.COLOR_* values.
- Return type:
- get_reflected_light(color)
Get detected light level.
- get_color()
Get detected color.
- Returns:
Detected color.
- Return type:
This also sets the sensor mode to color detection (light is cycling quickly to determine color).
- get_sample()
Get detected color.
- Returns:
Detected color.
- Return type:
This also sets the sensor mode to color detection (light is cycling quickly to determine color).
- class nxt.sensor.generic.Temperature(brick, port)
Bases:
BaseDigitalSensorLEGO Mindstorms NXT temperature sensor, part number 62840.
- get_deg_c()
Get the temperature in degrees Celsius.
- Returns:
Temperature in degrees Celsius.
- Return type:
- get_deg_f()
Get the temperature in degrees Fahrenheit.
- Returns:
Temperature in degrees Fahrenheit.
- Return type: