Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. package org.lejos.example;
  2.  
  3. import lejos.nxt.*;
  4. import lejos.robotics.navigation.DifferentialPilot;
  5.  
  6. /**
  7. * Write your code in main()
  8. */
  9. public class HelloWorld {
  10. static DifferentialPilot pilot = new DifferentialPilot(5.6, 17.5f, Motor.A, Motor.B);
  11. static UltrasonicSensor ultra = new UltrasonicSensor(SensorPort.S2);
  12. static LightSensor light = new LightSensor(SensorPort.S1);
  13.  
  14. public static void main(String[] args) {
  15. System.out.println("I'll be back!");
  16. Button.waitForAnyPress();
  17. Boolean movingForward = false;
  18. float angleBeforeAnotherDirection = 15
  19. pilot.setTravelSpeed(4);
  20. while(true){
  21. if (light.getValue() >= light.getHighValue()) {
  22. if (!movingForward){
  23. pilot.quickStop();
  24. if (!pilot.isMoving())
  25. movingForward = true;
  26. } else {
  27. pilot.travel(1);
  28. }
  29. } else {
  30. if (movingForward){
  31. pilot.quickStop();
  32. if (!pilot.isMoving()){
  33. pilot.rotateLeft(angleBeforeAnotherDirection, true);
  34. movingForward = false;
  35. }
  36. } else {
  37. if (!pilot.isMoving())
  38. pilot.rotateLeft(-1, true);
  39. }
  40.  
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement