View unanswered posts | View active topics It is currently Fri Oct 09, 2015 12:00 pm

Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Colour sensor 
Author Message
User avatar

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 148
Location: New Jersey
Ford Perfect, this is the basic code from HiTechnic...

Test HiTechnic Color Sensor

This program reads the HiTechnic color and displays the results on the screen.

The memory model for the HiTechnic Color Sensor is

Address Type Contents
00 - 07H chars Sensor version number
08 - 0FH chars Manufacturer
10 - 17H chars Sensor type
18 - 3DH bytes Not used
3E, 3FH chars Reserved
40H byte Not used
41H byte Reserved
42H byte Color number
43H byte Red reading
44H byte Green reading
45H byte Blue reading


task main()
int color, red, green, blue;

typedef struct{
byte nMsgSize;
byte nDeviceAddress;
byte nLocationPtr;
byte nCompassMode;
} TI2C_Output;

SensorType[S1] = sensorI2CCustomStd;
while(nI2CStatus[S1]== STAT_COMM_PENDING)

byte replyMessage[4];

TI2C_Output sOutput;

nxtDisplayTextLine(1, " HiTechnic");
nxtDisplayTextLine(2, "Color Sensor test");
nI2CBytesReady[S1] = 0;
sOutput.nMsgSize = 2; // go to read the values from the sensor
sOutput.nDeviceAddress = 0x02;
sOutput.nLocationPtr = 0x42;
sendI2CMsg(S1, sOutput.nMsgSize, sizeof(replyMessage));
// read from port 1

while (nI2CStatus[S1] == STAT_COMM_PENDING)

if (nI2CStatus[S1] == NO_ERR)
readI2CReply(S1, replyMessage[0], sizeof(replyMessage)); //get the color data starting from 0x42

color = (replyMessage[0] & 0x00FF);
red = (replyMessage[1] & 0x00FF);
green = (replyMessage[2] & 0x00FF);
blue = (replyMessage[3] & 0x00FF);

nxtDisplayTextLine(4, "color= %d", color);
nxtDisplayTextLine(5, "red val= %d", red);
nxtDisplayTextLine(6, "green val = %d", green);
nxtDisplayTextLine(7, "blue val = %d", blue);

Thu Mar 20, 2008 8:47 am
Profile WWW
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
thx a lot,
may be one (who wants and can test the result) is able to make a driver interface out of it!

HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}

Thu Mar 20, 2008 9:14 am
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 620
Hi Elizabeth,

We're committed to supporting users as much as possible and one of the biggest comments we've received has always been "Not enough documentation"

The ROBOTC team is currently working on creating a pretty comprehensive help system to help ROBOTC users. You can view the IFI version of this documentation here:

The Mindstorms version is currently in development and should have an initial version available for user review come Mid-Late April.

Timothy Friez
ROBOTC Developer - SW Engineer

Fri Mar 21, 2008 2:13 pm
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.