Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]
Files | Defines | Functions | Variables

Color Sensor V2
[HiTechnic]

Files

file  hitechnic-colour-v2.h
 

HiTechnic Color Sensor V2 driver.


Defines

#define HTCS2_I2C_ADDR   0x02
#define HTCS2_CMD_REG   0x41
#define HTCS2_OFFSET   0x42
#define HTCS2_COLNUM_REG   0x00
#define HTCS2_RED_REG   0x01
#define HTCS2_GREEN_REG   0x02
#define HTCS2_BLUE_REG   0x03
#define HTCS2_WHITE_REG   0x04
#define HTCS2_COL_INDEX_REG   0x05
#define HTCS2_RED_NORM_REG   0x06
#define HTCS2_GREEN_NORM_REG   0x07
#define HTCS2_BLUE_NORM_REG   0x08
#define HTCS2_RED_MSB   0x00
#define HTCS2_RED_LSB   0x00
#define HTCS2_GREEN_MSB   0x00
#define HTCS2_GREEN_LSB   0x00
#define HTCS2_BLUE_MSB   0x00
#define HTCS2_BLUE_LSB   0x00
#define HTCS2_WHITE_MSB   0x00
#define HTCS2_WHITE_LSB   0x00
#define HTCS2_MODE_ACTIVE   0x00
#define HTCS2_MODE_PASSIVE   0x01
#define HTCS2_MODE_RAW   0x03
#define HTCS2_MODE_50HZ   0x35
#define HTCS2_MODE_60HZ   0x36

Functions

int HTCS2readColor (tSensors link)
bool HTCS2readRGB (tSensors link, int &red, int &green, int &blue)
bool HTCS2readHSV (tSensors link, float &hue, float &saturation, float &value)
bool HTCS2readWhite (tSensors link, int &white)
bool HTCS2readNormRGB (tSensors link, int &red, int &green, int &blue)
bool HTCS2readRawRGB (tSensors link, bool passive, long &red, long &green, long &blue)
bool HTCS2readRawWhite (tSensors link, bool passive, long &white)
bool _HTCSsendCommand (tSensors link, byte command)
int HTCS2readColor (tMUXSensor muxsensor)
bool HTCS2readRGB (tMUXSensor muxsensor, int &red, int &green, int &blue)
bool HTCS2readHSV (tMUXSensor muxsensor, float &hue, float &saturation, float &value)
int HTCS2readColorIndex (tSensors link)

Variables

tConfigParams HTCS2_config = {HTSMUX_CHAN_I2C, 4, 0x02, 0x42}
tByteArray HTCS2_I2CRequest
tByteArray HTCS2_I2CReply
signed byte active_mode [4] = {-1, -1, -1, -1}

Detailed Description

HiTechnic Color Sensor V2


Define Documentation

#define HTCS2_BLUE_LSB   0x00

Raw blue reading - LSB

Definition at line 72 of file hitechnic-colour-v2.h.

#define HTCS2_BLUE_MSB   0x00

Raw blue reading - MSB

Definition at line 71 of file hitechnic-colour-v2.h.

#define HTCS2_BLUE_NORM_REG   0x08

Normalised blue reading

Definition at line 64 of file hitechnic-colour-v2.h.

#define HTCS2_BLUE_REG   0x03

Blue reading

Definition at line 59 of file hitechnic-colour-v2.h.

#define HTCS2_CMD_REG   0x41

Command register

Definition at line 52 of file hitechnic-colour-v2.h.

#define HTCS2_COL_INDEX_REG   0x05

Color index number

Definition at line 61 of file hitechnic-colour-v2.h.

#define HTCS2_COLNUM_REG   0x00

Color number

Definition at line 56 of file hitechnic-colour-v2.h.

#define HTCS2_GREEN_LSB   0x00

Raw green reading - LSB

Definition at line 70 of file hitechnic-colour-v2.h.

#define HTCS2_GREEN_MSB   0x00

Raw green reading - MSB

Definition at line 69 of file hitechnic-colour-v2.h.

#define HTCS2_GREEN_NORM_REG   0x07

Normalised green reading

Definition at line 63 of file hitechnic-colour-v2.h.

#define HTCS2_GREEN_REG   0x02

Green reading

Definition at line 58 of file hitechnic-colour-v2.h.

#define HTCS2_I2C_ADDR   0x02

HTCS2 I2C device address

Definition at line 51 of file hitechnic-colour-v2.h.

#define HTCS2_MODE_50HZ   0x35

Set sensor to 50Hz cancellation mode

Definition at line 80 of file hitechnic-colour-v2.h.

#define HTCS2_MODE_60HZ   0x36

Set sensor to 60Hz cancellation mode

Definition at line 81 of file hitechnic-colour-v2.h.

#define HTCS2_MODE_ACTIVE   0x00

Use ambient light cancellation

Definition at line 77 of file hitechnic-colour-v2.h.

#define HTCS2_MODE_PASSIVE   0x01

Disable ambient light cancellation

Definition at line 78 of file hitechnic-colour-v2.h.

#define HTCS2_MODE_RAW   0x03

Raw data from light sensor

Definition at line 79 of file hitechnic-colour-v2.h.

#define HTCS2_OFFSET   0x42

Offset for data registers

Definition at line 53 of file hitechnic-colour-v2.h.

#define HTCS2_RED_LSB   0x00

Raw red reading - LSB

Definition at line 68 of file hitechnic-colour-v2.h.

#define HTCS2_RED_MSB   0x00

Raw red reading - MSB

Definition at line 67 of file hitechnic-colour-v2.h.

#define HTCS2_RED_NORM_REG   0x06

Normalised red reading

Definition at line 62 of file hitechnic-colour-v2.h.

#define HTCS2_RED_REG   0x01

Red reading

Definition at line 57 of file hitechnic-colour-v2.h.

#define HTCS2_WHITE_LSB   0x00

Raw white channel reading - LSB

Definition at line 74 of file hitechnic-colour-v2.h.

#define HTCS2_WHITE_MSB   0x00

Raw white channel reading - MSB

Definition at line 73 of file hitechnic-colour-v2.h.

#define HTCS2_WHITE_REG   0x04

White channel reading

Definition at line 60 of file hitechnic-colour-v2.h.


Function Documentation

bool _HTCSsendCommand ( tSensors  link,
byte  command 
)

Send a command to the sensor to change its mode.

Parameters:
linkthe HTCS2 port number
commandthe command to be sent
Returns:
true if no error occured, false if it did

Definition at line 392 of file hitechnic-colour-v2.h.

int HTCS2readColor ( tSensors  link )

Return the color number currently detected.

Parameters:
linkthe HTCS2 port number
Returns:
color index number or -1 if an error occurred.
Examples:
hitechnic-colour-v2-SMUX-test1.c, and hitechnic-colour-v2-test1.c.

Definition at line 112 of file hitechnic-colour-v2.h.

int HTCS2readColor ( tMUXSensor  muxsensor )

Return the color number currently detected.

Parameters:
muxsensorthe SMUX sensor port number
Returns:
color index number or -1 if an error occurred.

Definition at line 135 of file hitechnic-colour-v2.h.

int HTCS2readColorIndex ( tSensors  link )

Return the color index number currently detected. This is a single 6 bit number color index. Bits 5 and 4 encode the red signal level, bits 3 and 2 encode the green signal level and bits 1 and 0 encode the blue signal levels.

Parameters:
linkthe HTCS2 port number
Returns:
color index number or -1 if an error occurred.

Definition at line 369 of file hitechnic-colour-v2.h.

bool HTCS2readHSV ( tMUXSensor  muxsensor,
float &  hue,
float &  saturation,
float &  value 
)

Get the detection levels for the hue, saturation, value components.

Parameters:
muxsensorthe SMUX sensor port number
huethe hue output value (from 0 to 365, or -1 if n/a)
saturationthe saruration output value (from 0 to 100, or -1 if n/a)
valuethe value output value (from 0 to 100)
Returns:
true if no error occured, false if it did

Definition at line 235 of file hitechnic-colour-v2.h.

bool HTCS2readHSV ( tSensors  link,
float &  hue,
float &  saturation,
float &  value 
)

Get the detection levels for the hue, saturation, value components.

Parameters:
linkthe HTCS port number
huethe hue output value (from 0 to 365, or -1 if n/a)
saturationthe saruration output value (from 0 to 100, or -1 if n/a)
valuethe value output value (from 0 to 100)
Returns:
true if no error occured, false if it did

Definition at line 216 of file hitechnic-colour-v2.h.

bool HTCS2readNormRGB ( tSensors  link,
int &  red,
int &  green,
int &  blue 
)

Get the normalised RGB readings. The normalization sets the highest value of the three Red, Green and Blue reading to 255 and adjusts the other two proportionately.

Parameters:
linkthe HTCS2 port number
redthe red value
greenthe green value
bluethe blue value
Returns:
true if no error occured, false if it did

Definition at line 281 of file hitechnic-colour-v2.h.

bool HTCS2readRawRGB ( tSensors  link,
bool  passive,
long &  red,
long &  green,
long &  blue 
)

Get the raw RGB readings, these are unsigned 16 bit values. These values will only fit in a long

Parameters:
linkthe HTCS2 port number
passivewhen set to true, it will not use the builtin white LED and use ambient light instead
redthe red value
greenthe green value
bluethe blue value
Returns:
true if no error occured, false if it did
Examples:
hitechnic-colour-v2-test2.c.

Definition at line 309 of file hitechnic-colour-v2.h.

bool HTCS2readRawWhite ( tSensors  link,
bool  passive,
long &  white 
)

Get the raw white channel reading, is and unsigned 16 bit value. This value will only fit in a long

Parameters:
linkthe HTCS2 port number
passivewhen set to true, it will not use the builtin white LED and use ambient light instead
whitethe white value
Returns:
true if no error occured, false if it did

Definition at line 340 of file hitechnic-colour-v2.h.

bool HTCS2readRGB ( tMUXSensor  muxsensor,
int &  red,
int &  green,
int &  blue 
)

Get the detection levels for the three color components.

Parameters:
muxsensorthe SMUX sensor port number
redthe red value
greenthe green value
bluethe blue value
Returns:
true if no error occured, false if it did

Definition at line 188 of file hitechnic-colour-v2.h.

bool HTCS2readRGB ( tSensors  link,
int &  red,
int &  green,
int &  blue 
)

Get the detection levels for the three color components.

Parameters:
linkthe HTCS2 port number
redthe red value
greenthe green value
bluethe blue value
Returns:
true if no error occured, false if it did
Examples:
hitechnic-colour-v2-SMUX-test1.c, and hitechnic-colour-v2-test1.c.

Definition at line 158 of file hitechnic-colour-v2.h.

bool HTCS2readWhite ( tSensors  link,
int &  white 
)

Get the detection level for the white channel.

Parameters:
linkthe HTCS2 port number
whitethe white channel value
Returns:
true if no error occured, false if it did

Definition at line 252 of file hitechnic-colour-v2.h.


Variable Documentation

signed byte active_mode[4] = {-1, -1, -1, -1}

Definition at line 104 of file hitechnic-colour-v2.h.

tConfigParams HTCS2_config = {HTSMUX_CHAN_I2C, 4, 0x02, 0x42}

Array to hold SMUX config data for sensor

Definition at line 97 of file hitechnic-colour-v2.h.

Array to hold I2C reply data Array to hold sensor modes

Definition at line 101 of file hitechnic-colour-v2.h.

Array to hold I2C command data

Definition at line 100 of file hitechnic-colour-v2.h.