Advertisement
Guest User

Linine TBN

a guest
May 5th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import lejos.nxt.Button;
  2. import lejos.nxt.LightSensor;
  3. import lejos.nxt.Motor;
  4. import lejos.nxt.NXTRegulatedMotor;
  5. import lejos.nxt.SensorPort;
  6.  
  7. /*
  8. * Motoren:
  9. * Links an A
  10. * Rechts an C
  11. *
  12. */
  13.  
  14. public class start {
  15.  
  16. private static final int BLACK = 50;
  17.  
  18. LightSensor sensorLinks = new LightSensor(SensorPort.S1);
  19. LightSensor sensorRechts = new LightSensor(SensorPort.S2);
  20.  
  21. NXTRegulatedMotor links = Motor.A;
  22. NXTRegulatedMotor rechts = Motor.C;
  23.  
  24. @SuppressWarnings("deprecation")
  25. private void starte() throws InterruptedException {
  26.  
  27. System.out.println("Folge der Linie......");
  28.  
  29. // so lange bis escape button gedrueckt ist
  30. while (!Button.ESCAPE.isDown()) {
  31.  
  32. if (sensorLinks.getLightValue() < BLACK) {
  33.  
  34. // wenn der linke sensor auf der linie ist, drehe nach links
  35. links.backward();
  36. rechts.forward();
  37.  
  38. } else if (sensorRechts.getLightValue() < BLACK) {
  39.  
  40. // wenn der rechte sensor auf der linie ist, drehe nach rechts
  41. links.forward();
  42. rechts.backward();
  43. } else {
  44.  
  45. // sonst vorwaerts fahren
  46. links.forward();
  47. rechts.forward();
  48.  
  49. }
  50.  
  51. Thread.sleep(10); // absturz verhindern
  52.  
  53. }
  54.  
  55. }
  56.  
  57. /**
  58. * @param args
  59. */
  60. public static void main(String[] args) {
  61. try {
  62. // erstellt eine neue Instanz und ruft starte() auf
  63. new start().starte();
  64. } catch (InterruptedException e) {
  65. // passiert eigentlich nie
  66. }
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement