This is where you talk about the NXJ software itself, installation issues, and programming talk.
Moderators: roger, 99jonathan, imaqine
by javareds » Mon Mar 18, 2013 1:18 pm
I use the following code and no matter what color paper i put under the sensor the values are always the same.
Thanks for any help.
- Code: Select all
package colorread;
import lejos.nxt.*;
import lejos.robotics.Color;
public class colorread {
public static void main (String[] args)throws Exception {
ColorSensor cs = new ColorSensor(SensorPort.S4, SensorConstants.TYPE_LIGHT_ACTIVE);
TouchSensor ts = new TouchSensor(SensorPort.S3);
LCD.clearDisplay();
LCD.drawString("" + cs.getColor(), 0,0);
LCD.drawString("" + cs.getColor(), 0,1);
LCD.drawString("" + cs.getColor(), 0,2);
LCD.drawString("" + cs.getColor(), 0,3);
LCD.drawString("" + cs.getColor(), 0,4);
while(!ts.isPressed()){
}//end wait to start
}
}
-
javareds
- New User
-
- Posts: 1
- Joined: Mon Mar 18, 2013 1:15 pm
by gloomyandy » Mon Mar 18, 2013 2:47 pm
Why are you setting the type to TYPE_LIGHT_ACTIVE? If you want to use the sensor to detect colors use the simpler constructor that just takes the port number. You should also look at the color sensor sample that will give you a better understanding of how to use the device.
https://sourceforge.net/p/lejos/code/69 ... rTest.javaAlso which color sensor are you trying to use. There are two, one from Lego and one from HiTechnics make sure you are using the appropriate leJOS class.
-

gloomyandy
- leJOS Team Member
-
- Posts: 3004
- Joined: Fri Sep 28, 2007 2:06 pm
- Location: UK
by skoehler » Fri Mar 22, 2013 2:47 am
Actually, the second parameter of the constructor is supposed to be a color! Not some kind of type.
-
skoehler
- leJOS Team Member
-
- Posts: 1114
- Joined: Thu Oct 30, 2008 4:54 pm
Return to NXJ Software
Who is online
Users browsing this forum: No registered users and 4 guests