GetNXT2Color

Reads the current value of the color sensor from the NXT 2.0 set

Contents

Syntax

out = GetNXT2Color(port)

out = GetNXT2Color(port, handle)

Description

This functions retrieves the current value 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.

The sensor has to be opened with OpenNXT2Color() before this function can be used.

Depending on the mode the color sensor was opened in, the return value of this function can have one of the following two formats

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

OpenNXT2Color, CloseSensor, OpenColor, GetColor, OpenLight, GetLight, COM_ReadI2C,

Signature