Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import lejos.nxt.Button;
- import lejos.nxt.LightSensor;
- import lejos.nxt.Motor;
- import lejos.nxt.NXTRegulatedMotor;
- import lejos.nxt.SensorPort;
- /*
- * Motoren:
- * Links an A
- * Rechts an C
- *
- */
- public class start {
- private static final int BLACK = 50;
- LightSensor sensorLinks = new LightSensor(SensorPort.S1);
- LightSensor sensorRechts = new LightSensor(SensorPort.S2);
- NXTRegulatedMotor links = Motor.A;
- NXTRegulatedMotor rechts = Motor.C;
- @SuppressWarnings("deprecation")
- private void starte() throws InterruptedException {
- System.out.println("Folge der Linie......");
- // so lange bis escape button gedrueckt ist
- while (!Button.ESCAPE.isDown()) {
- if (sensorLinks.getLightValue() < BLACK) {
- // wenn der linke sensor auf der linie ist, drehe nach links
- links.backward();
- rechts.forward();
- } else if (sensorRechts.getLightValue() < BLACK) {
- // wenn der rechte sensor auf der linie ist, drehe nach rechts
- links.forward();
- rechts.backward();
- } else {
- // sonst vorwaerts fahren
- links.forward();
- rechts.forward();
- }
- Thread.sleep(10); // absturz verhindern
- }
- }
- /**
- * @param args
- */
- public static void main(String[] args) {
- try {
- // erstellt eine neue Instanz und ruft starte() auf
- new start().starte();
- } catch (InterruptedException e) {
- // passiert eigentlich nie
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement