Skip to content

brian.sensors.NXT.LightSensorNXT

brian.sensors.NXT

LightSensorNXT class objects

class LightSensorNXT(Sensor)

Class for interacting with NXT light sensor.

Sensor is automatically registered in the constructor of the base class and un-registered in its destructor. It can also be unregistered with the LightSensorNXT.close_sensor() function.

There can be at most one instance at any given time, of any sensor class per port in the entire program.

__init__

def __init__(port: SensorPort)

Initialize an NXT light sensor at the given port.

Arguments:

  • port: Sensor port to which the sensor is attached.

Mode class objects

class Mode(Enum)

LED_OFF

LED_ON

set_mode

def set_mode(mode: Mode) -> None

This function sets the sensor to the desired mode. While it’s not mandatory, it is recommended to call this

function before accessing values from the sensor in a specific mode to prevent SensorIsNotReady exceptions.

Arguments:

  • mode: desired mode to be set

light_value

def light_value(led_on: bool) -> float

Measures incoming light.

Arguments:

  • led_on: whether the red LED should be on or off

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready.

Returns:

Value in range 0-1, with 0 being the darkest and 1 being the brightest.

light_value_raw

def light_value_raw(led_on: bool) -> int

Measures incoming light. Raw measurement is inverted, meaning lower values correspond to brighter light.

Arguments:

  • led_on: whether the red LED should be on or off

Raises:

  • brian.sensors.SensorIsNotReadyError: If the sensor is not ready.

Returns:

Value in range 0-4095, with 4095 being the darkest and 0 being the brightest.