GetColor
Reads the current value of the HiTechnic Color sensor
Contents
Syntax
[index r g b] = GetColor(port)
[index r g b] = GetColor(port, handle)
Description
degree = GetColor(port) returns the index color value and the RGB-values of the HiTechnic Color sensor. The color index for mode=0 and mode=1 corresponds to the following table, but the color values don't be pure RGB-values. Tests give best results for RGB-colors in brackets:
% 0 = black (0-0-0) % 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 color index (0..63) for mode=2 and mode=3 will return a 6 bit color index number, which encodes red in bit 5 an 4, green in bit 3 and 2 and blue in bit. It gives good results to identify a color by one value.
The RGB-Values will be returned depending on the mode parameter mode = 0 : RGB = the current detection level for the color components red, green and blue in an range of 0 to 255 mode = 1 : RGB = the current relative detection level for the color components red, green and blue in an range of 0 to 255. The highest value of red, green and blue is set to 255 and the other components are adjusted proportionally. mode = 2 : RGB = the analog signal levels for the three color components red, green and blue with an accurancy of 10 bit (0 to 1023). mode = 3 : RGB = the current relative detection level for the color components red, green and blue in an range of 0 to 3.
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 functions NXT_LSRead and NXT_LSWrite 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).
Example
OpenColor(SENSOR_4); [index r g b] = GetColor(SENSOR_4, 0); CloseSensor(SENSOR_4);
See also
OpenColor, CalibrateColor, CloseSensor, COM_ReadI2C,
Signature
- Author: Rainer Schnitzler, Linus Atorf (see AUTHORS)
- Date: 2008/10/01
- Copyright: 2007-2009, RWTH Aachen University