Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.lejos.example;
- import lejos.nxt.*;
- import lejos.robotics.navigation.DifferentialPilot;
- /**
- * Write your code in main()
- */
- public class HelloWorld {
- static DifferentialPilot pilot = new DifferentialPilot(5.6, 17.5f, Motor.A, Motor.B);
- static UltrasonicSensor ultra = new UltrasonicSensor(SensorPort.S2);
- static LightSensor light = new LightSensor(SensorPort.S1);
- public static void main(String[] args) {
- System.out.println("I'll be back!");
- Button.waitForAnyPress();
- Boolean movingForward = false;
- float angleBeforeAnotherDirection = 15
- pilot.setTravelSpeed(4);
- while(true){
- if (light.getValue() >= light.getHighValue()) {
- if (!movingForward){
- pilot.quickStop();
- if (!pilot.isMoving())
- movingForward = true;
- } else {
- pilot.travel(1);
- }
- } else {
- if (movingForward){
- pilot.quickStop();
- if (!pilot.isMoving()){
- pilot.rotateLeft(angleBeforeAnotherDirection, true);
- movingForward = false;
- }
- } else {
- if (!pilot.isMoving())
- pilot.rotateLeft(-1, true);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement