Using RobotC, on the Lego NXT 'bot, the Color Sensor (by Lego) will correctly identify colors using the View tab, ColorSensor tab, ie when not programmed in from RobotC. When I write a program that uses the color sensor to move when on specific color, the color sensor doesn’t seem to detect color.
task main {
if (SensorValue (colorSensor == yellow))
motor[motorA] = 50;
motor[motorC] = 50;
}
Or, if the 'bot is on a white surface going forward and to stop at a black line,
if (SensorValue (colorSensor != black))
motor[motorA] = 50;
motor[motorC] = 50;
The commands compile and download OK.
The color sensor doesn’t work any better when placed in another port. The color ssensors emitting LED doesn’t appear to “shine” during the program. I tried the short program from BotBench that uses a while loop and switch/case command to test color sensing and this program works correctly.
I went back and tried to declare each color as a variable - see below:
task main ()
{
string sColor1;
sColor1 = “BLACKCOLOR”;
string sColor2;
sColor2 = “BLUECOLOR”;
string sColor3;
sColor3 = “YELLOWCOLOR”;
string sColor4;
sColor4 = “???”
if (SensorValue (lightSensor == sColor4))
{
nSyncedMotors = synchAC;
nSyncedTurnRatio = 100;
motor [motorA] = 70;
}
else (SensorValue (lightSensor == sColor1));
{
motor[motorC] = -70;
motor{motorA] = -70;
wait1msec (500);
motor[motorC] = 70;
motor[motorA] = -70;
wait1Msec (1000);
}
}
when compiling - the error message is: 1. Invalid comparison with 'char and ‘string’ types. 2. internal compiler Mixed mode (string/byte) comparison in conditional branch.
Any help you can give me on getting started with the color sensor would be appreciated. Also, I can’t find any examples of code used in a program that uses the color sensor, out on the web, any suggestions?
Thanks in advance - Dave