GetColor

Reads the current value of the HiTechnic Color V1 or V2 sensor

Contents

Syntax

[index r g b] = GetColor(port, mode)

[index r g b] = GetColor(port, mode, handle)

Description

This function returns the color index and the RGB-values of the HiTechnic Color sensor. There are two different hardware versions of the sensor.

The color index values roughly correspond to the following table (when using modes 0 and 1):

%	    0 = black
%	    1 = violet
%	    2 = purple
%	    3 = blue
%	    4 = green
%	    5 = lime
%	    6 = yellow
%	    7 = orange
%	    8 = red
%	    9 = crimson
%	    10 = magenta
%	    11 to 16 = pastels
%	    17 = white

The RGB-Values will be returned depending on the mode parameter.

The color index (0..63) for mode 2 and mode 3 will return a 6 bit color index number, which encodes red in bit 5 and 4, green in bit 3 and 2 and blue in bit 1 (?).

The given port number specifies the connection 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.

For more complex settings the function COM_ReadI2C can be used.

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

It's by design that the white LED of the Color sensors cannot be turned off by calling CloseSensor. It's always on when the sensor is connected. The V2 hardware version of the sensor performs significantly better than the V1 version.

Example

   OpenColor(SENSOR_4);
   [index r g b] = GetColor(SENSOR_4, 0);
   CloseSensor(SENSOR_4);

See also

OpenColor, CalibrateColor, CloseSensor, OpenNXT2Color, GetNXT2Color, COM_ReadI2C,

Signature