- Code: Select all
import lejos.nxt.*;
import lejos.util.*;
import lejos.robotics.navigation.*;
public class manuel
{
Stopwatch sw = new Stopwatch();
int sport1, sport2, wport1, wport2;
//Scharz- und Weiss-Werte für Lichtsensor 1,2
int midpoint1, midpoint2; //Mittelpunkte
int port1c, port2c; //Variablen fuer aktuellen Lichtwert für Port 1 und 2
boolean port1r, port2r;
LightSensor licht1 = new LightSensor(SensorPort.S1);
//Lichtsensor rechts an Port1
// Ambient Light on
LightSensor licht2 = new LightSensor(SensorPort.S3);
//Lichtsensor links an Port3
// Ambient Light on
Motor [] m = {Motor.A, Motor.B};
/**
* @param args
* @author Manuel und Timo
*/
public static void main(String[] args)
{
LCD.drawString("schwarze Linie", 0, 1);
new manuel().Configuration();
new manuel().go();
}
public void go()
{
boolean ButtonPressed = false;
while(ButtonPressed = false)
{
new manuel().aktuellerLichtwertMessen();
new manuel().RichtungsEntscheidung();
if(Button.isPressed(true)) ButtonPressed = true;
//The method isPressed() in the type Button is not applicable for the arguments (boolean)
}
}
public void Configuration()
{
while(sw.elapsed() < 5000)
{
sw.reset();
LCD.clear();
LCD.drawString("Bitte beide",0,0);
LCD.drawString("Sensoren auf",0,1);
LCD.drawString("schwarz setzen",0,2);
sport1 = licht1.getLightValue();
sport2 = licht2.getLightValue();
}
while(sw.elapsed() < 5000)
{
sw.reset();
LCD.clear();
LCD.drawString("Bitte beide",0,0);
LCD.drawString("Sensoren auf",0,1);
LCD.drawString("weiss setzen",0,2);
wport1 = licht1.getLightValue();
wport2 = licht2.getLightValue();
LCD.clear();
}
midpoint1 = ((wport1 + sport1)/2);
midpoint2 = ((wport2 + sport2)/2);
}
public void aktuellerLichtwertMessen()
{
port1c = licht1.getLightValue();
//Messergebnis von Port1 als integere Zahl
port2c = licht2.getLightValue();
//Messergebnis von Port3 als integere Zahl
if(port1c > midpoint1) port1r = true;
if(port1c < midpoint1) port1r = false;
//else port1r = false;
if(port2c > midpoint2) port2r = true;
if(port2c < midpoint2) port2r = false;
//else port2r = false
}
public void RichtungsEntscheidung()
{
aktuellerLichtwertMessen();
if(port1r = true) if(port2r = false)
for(int i = 0; i<2; i++)m[i].forward();
else
for(int i = 0; i<2; i++)m[i].rotateRight();
//The method rotateRight() is undefined for the type Motor
if(port1r = false) if(port2r = true)
for(int i = 0; i<2; i++)m[i].rotateLeft();
//The method rotateLeft() is undefined for the type Motor
else BBError();
}
}
BBError() is not programmed yet. You can ignore this fault.
Thanks for help! legott
