How to get lightvalue from EV3ColorSensor

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

Moderators: roger, gloomyandy, skoehler

New User
Posts: 22
Joined: Fri Oct 25, 2013 8:04 pm

How to get lightvalue from EV3ColorSensor

Postby cfin » Sat Jan 11, 2014 3:24 pm

With the 0.4.0 release I could do the following:

Code: Select all

UARTPort uPort = new LocalUARTPort();
      if (! {
         System.out.println("Open failed");
      colorSensor = new EV3ColorSensor(uPort);

But now, the colorSensor does not have the method getLightValue anymore.
The only interface with this method, I found is LightDetector. But there seems no implementation existing.

If it is still possible to access the lightvalue, could someone please give me some codeline, how to access the lightvalue?

Thank you,

leJOS Team Member
Posts: 253
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

Re: How to get lightvalue from EV3ColorSensor

Postby Aswin » Sat Jan 11, 2014 3:41 pm


Please read the wiki on changes regarding sensors.
I think you'll find your answer there.

My NXT blog:

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

Re: How to get lightvalue from EV3ColorSensor

Postby gloomyandy » Sat Jan 11, 2014 4:02 pm

In 0.5.0 we introduced a new more general sensor interface (see Aswin's post or the Wiki for more details). So you need to obtain the appropriate sensor mode interface, each sensor exports a number of modes which in turn have a sample provider which can be used to obtain the data. In the case of the EV3ColorSensor it provides 4 modes ColorIDMode, RedMode, RGBMode and AmbientMode each of which can be obtained via a call like getRedMode() etc., note that RGB mode is not currently working. So to obtain a reading for the sensor with the red led on, you use RedMode to obtain a background reading (with no illumination) you use AmbientMode. In each case you need to use the fetchSample method to obtain the data and sampleSize to determine how many values will be returned (and hence how big an array you need to provide to fetchSample).

Also note that you no longer need to open the sensor port. Instead you can either use one of the convenience variables (S1, S2 etc.) or you can use the more general form:
and then simply pass the returned Port object into the constructor for the sensor driver.
As always if you don't understand something you can always look at the source: ...
or look at the sample code we provide: ...

Return to “EV3 Software”

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests