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

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 (!uPort.open(2)) {
         System.out.println("Open failed");
         return;
      }
      colorSensor = new EV3ColorSensor(uPort);
colorSensor.getLightValue()

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,
cfin
cfin
New User
 
Posts: 15
Joined: Fri Oct 25, 2013 8:04 pm

Re: How to get lightvalue from EV3ColorSensor

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

Hi,

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

Aswin
My NXT blog: http://nxttime.wordpress.com/
Aswin
leJOS Team Member
 
Posts: 206
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands

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:
BrickFinder.getDefault().getPort("S1")
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:
https://sourceforge.net/p/lejos/ev3/ci/ ... ensor.java
or look at the sample code we provide:
https://sourceforge.net/p/lejos/ev3/ci/ ... rTest.java
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4181
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 4 guests

more stuff