Moderator: roger
import josx.platform.rcx.*;
import josx.robotics.*;
//////////////////////////////////////
/**
* Line follower
*
* @author Adam Christianson
* @url http://www.terraform.com
* @version 1.0
*/
public class LineFollow {
////////////////////////////////////////////
// public methods
////////////////////////////////////////////
////////////////////////////////////////////
/**
* main method
* @throws InterruptedException
*/
public static void main(String[] args)
throws InterruptedException {
Sensor.S1.setTypeAndMode (3, 0x80);
Sensor.S1.activate();
Sensor.S1.addSensorListener (new SensorListener() {
public void stateChanged (Sensor src, int oldValue, int newValue) {
// Will be called whenever sensor value changes
LCD.showNumber(newValue);
TimingNavigator robot = new TimingNavigator(Motor.C, Motor.A, 1.6f, 0.54f);
if (newValue > 35 ) {
robot.travel(-15);
pause(300);
robot.rotate(-45);
pause(300);
} else {
robot.forward();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignore
}
}
});
// just run until RUN button is pressed again
Button.RUN.waitForPressAndRelease();
} //main()
public static void pause(int delay)
{
try { Thread.sleep(delay); }
catch (InterruptedException ie) { }
}
}
JavaMan wrote:Yes, the light sensor for the RCX can only detect light intensity levels. So, usually black has a lower intensity and white has a higher intensity. Gray would have a intensity somewhere in the middle. It can't detect different wavelengths. Here is a site I found describing how to build a Color Sensor
http://www.extremenxt.com/MUX2.HTM for the RCX.
Hope that helps.
Jman
Users browsing this forum: No registered users and 0 guests