Light sensor does nothing

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc

Moderators: roger, 99jonathan, imaqine

Light sensor does nothing

Postby janvos2506 » Wed Oct 26, 2011 9:42 pm

Hey,
I am making a segway,everything went fine and all but then i got to program the light sensor.
Now here the light sensor doesn't give light it doesn't output anything except the highest value possible.
help?
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Light sensor does nothing

Postby gloomyandy » Thu Oct 27, 2011 12:30 am

What sort of light sensor do you have (the original version from the first NXT kit, or the color sensor from the newer kit)?
Post your code (or even better a short test program that shows up the problem).
What version of leJOS are you using?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Light sensor does nothing

Postby janvos2506 » Thu Oct 27, 2011 10:33 am

Hey thanks for you response.
I'm using the color sensor from the NXT2.0 original set.
LeJOS beta 9
and i tried running a short sample but does nothing :(
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Light sensor does nothing

Postby gloomyandy » Thu Oct 27, 2011 11:02 am

So post your sample code...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Light sensor does nothing

Postby janvos2506 » Thu Oct 27, 2011 11:29 am

okay here it is :

Code: Select all
import lejos.nxt.*;

public class LightTest {
  public static void main(String[] args) throws Exception {
    LightSensor light = new LightSensor(SensorPort.S1);

    while (true) {
      LCD.drawInt(light.getLightValue(), 4, 0, 0);
      LCD.drawInt(light.getNormalizedLightValue(), 4, 0, 1);
      LCD.drawInt(SensorPort.S1.readRawValue(), 4, 0, 2);
      LCD.drawInt(SensorPort.S1.readValue(), 4, 0, 3);
    }
  }
}      
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm

Re: Light sensor does nothing

Postby gloomyandy » Thu Oct 27, 2011 12:31 pm

You are using the wrong sensor class if you are using the Lego Color sensor you need to use the ColorSensor class...
http://lejos.sourceforge.net/nxt/nxj/ap ... ensor.html
You can take a look at the sample code which shows how you can use this sensor. The sample ColorSensorTest is located in the samples directory that will have been installed as part of the leJOS install. You can view the sample on line here:
http://lejos.svn.sourceforge.net/viewvc ... iew=markup
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Light sensor does nothing

Postby janvos2506 » Thu Oct 27, 2011 8:45 pm

Oh stupid of me...
But thanks got it working!!
janvos2506
Novice
 
Posts: 34
Joined: Mon Oct 24, 2011 8:58 pm


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff