Color Sensor - How do I turn on the light?

I am a newbie trying to learn Graphical ROBOTC for VEX IQ in order to help mentor a brand new team. I built the clawbot with sensors according to instructions and am now learning how to program the sensors. I’m confused about the color sensor. I want to do the following:

  • drive forward until a black line is detected
  • turn left
The problem is that sometimes when I run the program, the color sensor white light is on, shining down on the surface of the playing field. When the light is on, the program works great. But sometimes (especially if I've pressed the X button on the robot brain and then download the program), the light is not initially on. And in this case, it's dark and therefore the robot doesn't drive forward.

How do I initialize the color sensor to turn the light on before running the rest of the program? There’s no command in the graphical interface to initialize or reset the color sensor.

Note: I have ROBOTC interface set up to show the Debug windows for the sensors. When the light is off, the color sensor doesn’t even show up in the sensors debug window. When the light is on, I get valid values. So it all comes down to the light!

The motor and sensor configuration is Clawbot (with sensors) with the only modification being the color sensor set to grayscale.

e769a994b8fc551004791183f9bcc9de.jpg

FYI - I did discover if I converted the graphical program to C and added the following 2 lines of code at the beginning of the procedure, I could force the light to turn on. BUT…my kids aren’t up to writing in C yet. I need a way to do with with the graphical interface.

setColorMode(colorDetector, colorTypeGrayscale_Reflected);
sleep(1000);

The sleep command was required because it takes a small bit of time for the light to turn on. I suspect the 1000 can be a smaller value but I didn’t experiment with the threshold.

Debbie,

I’m not totally sure about this, but in the graphic mode, try putting a command to check the light sensor (like you have in your loop) as an “if” statement, and then add the wait. That should force it to turn on the sensor the same way you’re doing in the text.

Does that make sense?

Steve

I did try putting in a check for the light sensor in a ‘if’ statement but it didn’t work. I finally found a solution. I added a 500ms delay at the very beginning of the program prior to doing anything at all. This delay seemed to provide enough time for the light to turn on so that the following code worked. There is no way to “setColorMode” via the graphical interface but there is a Wait command in graphical which is what I used to program the delay.

In my program last year the light on the color sensor turned on automatically. This program was made in text-based robotC.

Though it might have been because I had the color sensor surrounded by plastic to keep it in the dark. And yes, it was set up to be a line follower.