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 old Color sensor V1 has a single weak LED which is always on once connected. You can spot little red, green and blue lights behind the milky lens. This sensor can be calibrated using the function CalibrateColor. It has sometimes trouble getting accurate results. You can use all values for mode. Try which one works best for you.
- The new Color sensor V2 has a single bright white LED which is always flashing once connected. The lens is relatively clear. This sensor gives great accuary for most colors, even at some distance. Only mode = 0 is supported. Other modes will return wrong values. The sensor works fine as it comes, it SHOULD NOT BE CALIBRATED.
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.
- mode = 0 : RGB = the current detection level for the color components red, green and blue in an range of 0 to 255. Use this setting for color sensor V2
- 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. Only V1.
- 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). Only V1.
- mode = 3 : RGB = the current relative detection level for the color components red, green and blue in an range of 0 to 3. Only V1.
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
- Author: Rainer Schnitzler, Linus Atorf (see AUTHORS)
- Date: 2010/09/16
- Copyright: 2007-2010, RWTH Aachen University