OpenNXT2Color

Initializes the LEGO color sensor from the NXT 2.0 set, sets correct sensor mode

Contents

Syntax

OpenNXT2Color(port, mode)

OpenNXT2Color(port, mode, handle)

Description

This function initializes the input mode of the LEGO NXT 2.0 Color sensor specified by the sensor port. The value port can be addressed by the symbolic constants SENSOR_1 , SENSOR_2, SENSOR_3 and SENSOR_4 analog to the labeling on the NXT Brick. This function is intended for the Color sensor that comes with the NXT 2.0 set. It has the label "RGB" written on the front, 3 LED openings (1 black empty spot, the light sensor and a clear lens with tiny red, green, blue LEDs behind it). It is not to be confused with the HiTechnic Color sensors (V1 and V2), for those please see the functions OpenColor and GetColor.

With GetNXT2Color(port) you can receive the detected brightness or color.

mode specifies the operating mode of the sensor, the following values are allowed:

The last optional argument can be a valid NXT handle. If none is specified, the default handle will be used (call COM_SetDefaultNXT to set one).

Limitations

The sensor is influenced by ambient light. It reacts differently on daylight than on artificial light. The modes 'RED' and 'NONE' are similar to the Light sensor's modes 'ACTIVE' and 'INACTIVE', but the sensors are not perfectly compatible.

Examples

  port = SENSOR_1;
  OpenNXT2Color(port, 'FULL');
  color = GetNXT2Color(port);
  if strcmp(color, 'BLUE')
      disp('Blue like the ocean');
  else
      disp(['The detected color is ' color]);
  end%if
  CloseSensor(port);
  port = SENSOR_2;
  OpenNXT2Color(port, 'NONE');
  colorVal = GetNXT2Color(port);
  if colorVal > 700
      disp('It''s quite bright!')
  end%if
  CloseSensor(port);

See also

GetNXT2Color, CloseSensor, OpenColor, GetColor, OpenLight, GetLight, COM_ReadI2C,

Signature