Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import lejos.hardware.motor.EV3LargeRegulatedMotor;
  2. import lejos.hardware.port.MotorPort;
  3. import lejos.hardware.port.SensorPort;
  4. import lejos.hardware.sensor.EV3ColorSensor;
  5. import lejos.hardware.sensor.EV3UltrasonicSensor;
  6. import lejos.robotics.RegulatedMotor;
  7. import lejos.hardware.Button;
  8.  
  9. public class ev3 {
  10.  
  11. public static void main(String args[]) {
  12. int x = 0;
  13. try {
  14.  
  15. EV3UltrasonicSensor augen = new EV3UltrasonicSensor (SensorPort.S3);
  16. System.out.println(" _.-;;-._");
  17. System.out.println("'-..-'| || |");
  18. System.out.println("'-..-'|_.-;;-._|");
  19. System.out.println("'-..-'| || |");
  20. System.out.println("'-..-'|_.-''-._|");
  21.  
  22. EV3ColorSensor colorSensor = new EV3ColorSensor(SensorPort.S1);
  23. RegulatedMotor links = new EV3LargeRegulatedMotor(MotorPort.A);
  24. RegulatedMotor rechts = new EV3LargeRegulatedMotor(MotorPort.B);
  25.  
  26. colorSensor.setCurrentMode(1);
  27. links.forward();
  28. rechts.forward();
  29. augen.enable();
  30.  
  31. while (Button.ESCAPE.isUp()) {
  32.  
  33. float temp[] = new float[1];
  34. colorSensor.getRedMode().fetchSample(temp, 0);
  35.  
  36. if (temp[0] < 0.2 && Button.ESCAPE.isUp()) { // falls Schwarz
  37. x = 0;
  38. links.setSpeed(50);
  39. rechts.setSpeed(100);
  40. }
  41. if (temp[0] > 0.2 && Button.ESCAPE.isUp()) {
  42. links.setSpeed(50+(x/300));
  43. rechts.setSpeed(100);
  44. x++;
  45. }
  46. // if (augen.getDistanceMode().sampleSize()<0.05)
  47. // {
  48. // Thread.sleep(2500);
  49. // }
  50.  
  51.  
  52. }
  53. } catch (Exception e) {
  54.  
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement