Confusing ColorLightSensor API/controlling LEDs

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Confusing ColorLightSensor API/controlling LEDs

Postby Gatanui » Tue Mar 06, 2012 10:01 pm

How do I control the corresponding LEDs of the standard Mindstorms colour light sensor via the methods of the ColorLightSensor class? I find the API slightly confusing and the sample program did not help me very much either. Apparently, I can use the method setFloodlight() adressing the enum constants of the Colors.Color class. But how exactly? Can anyone please explain in a more detailed way the ColorLightSensor class and the methods relevant for controlling the LEDs?

Thanks in advance,

Gatanui
Gatanui
New User
 
Posts: 13
Joined: Thu Jun 16, 2011 2:08 pm

Re: Confusing ColorLightSensor API/controlling LEDs

Postby skoehler » Tue Mar 06, 2012 10:59 pm

ColorLightSensor does not exist (at least not in 0.9.1). Are you using ColorHTSensor?
skoehler
leJOS Team Member
 
Posts: 1422
Joined: Thu Oct 30, 2008 4:54 pm

Re: Confusing ColorLightSensor API/controlling LEDs

Postby Gatanui » Wed Mar 07, 2012 11:28 am

The ColorLightSensor class does exist(?) In fact, the method setFloodlight() works perfectly for boolean values when I upload my compiled test program onto the NXT brick. However, since I don't specify which LED I want to be turned on, it's always the red one that lights up, although I want to control the LEDs individually. The question is: How exactly do I do that? What would a statement to turn on the blue LED, for example, look like?

~Gatanui
Gatanui
New User
 
Posts: 13
Joined: Thu Jun 16, 2011 2:08 pm

Re: Confusing ColorLightSensor API/controlling LEDs

Postby skoehler » Wed Mar 07, 2012 12:36 pm

I took a look at the 0.9.1 implementation. It accepts an integer instead of color objects and it allows you to chose between red, blue, green, none, and white.
I don't personally own this sensor, and I believe that settings the floodlight color might not mean what you expect. AFAIK, the sensor doesn't have a white LED. Instead, setting the floodlight to white might mean, that when the sensor is measuring, the LED will be switched between the three colors red blue green really quick. I'm not sure, whether settings the flood light to one of the elementary colors will immediately change the color of the LED. You might have to call read() once.
Try

setFloodLight(lejos.robotics.Colors.Color.BLUE);
readValue();
skoehler
leJOS Team Member
 
Posts: 1422
Joined: Thu Oct 30, 2008 4:54 pm

Re: Confusing ColorLightSensor API/controlling LEDs

Postby gloomyandy » Wed Mar 07, 2012 2:25 pm

For the Lego color sensor setting the floodlight color will change the color output immediately for red/green/blue, but not for white (which as Sven mentioned is really just rapid red/green/blue output during the color sensing stage)...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4081
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Confusing ColorLightSensor API/controlling LEDs

Postby Gatanui » Thu Mar 08, 2012 10:58 am

Thanks for the help! The method works perfectly. Now I am just wondering how to arrange it to simulate composed colours like magenta, for example. I tried quickly switching between blue and red, but it seems setFloodlight() is a slow method, so a switch in a matter of milliseconds does not seem to be possible with this method. Is this correct? And if it is, is there a way I can do this quick switch anyway?

~Gatanui
Gatanui
New User
 
Posts: 13
Joined: Thu Jun 16, 2011 2:08 pm

Re: Confusing ColorLightSensor API/controlling LEDs

Postby gloomyandy » Thu Mar 08, 2012 11:30 am

I don't think there is anyway you can quickly switch the color modes. Basically a mode switch requires a reset of the device which takes time...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4081
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Confusing ColorLightSensor API/controlling LEDs

Postby Gatanui » Thu Mar 08, 2012 11:55 am

But how does white/TYPE_COLORFULL work then? It can only work if all LEDs are turned on at the same time or if they switch very quickly.

~Gatanui
Gatanui
New User
 
Posts: 13
Joined: Thu Jun 16, 2011 2:08 pm

Re: Confusing ColorLightSensor API/controlling LEDs

Postby gloomyandy » Thu Mar 08, 2012 12:39 pm

That is a mode of the sensor. The hardware takes care of switching the LED between red/green/blue very rapidly when using TYPE_COLORFULL. The sensor operates in one of 5 modes, full color (in this mode the sensor actually takes four readings one for each color plus a background level, in the other modes the sensor only reads a single value), red, green, blue, and none. There is only a single tri-color LED in the sensor which is switched by the logic in the device. Remember that this device is intended to simply detect the basic Lego colors and act as an alternative to the original Lego light sensor. It's not designed to be used for a light show!

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4081
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

more stuff