View unanswered posts | View active topics It is currently Sat Nov 29, 2014 3:40 am






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

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

Quote:
/*
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;
wait10Msec(5);
nI2CBytesReady[S1]=0;
while(nI2CStatus[S1]== STAT_COMM_PENDING)
wait1Msec(2);

byte replyMessage[4];

TI2C_Output sOutput;

while(true)
{
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)
wait1Msec(2);

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);
wait1Msec(125);
}
}
}


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

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

_________________
regards,
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
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 614
Post 
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: http://www.robotc.net/ifi_webhelp/

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
tfriez@robotc.net


Fri Mar 21, 2008 2:13 pm
Profile
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:  
cron



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