

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


import lejos.nxt.*; public class HelloWorld { public static void main (String[] args) { System.out.println("Hello World"); Button.waitForPress(); } }
import lejos.nxt.; import java.lang.;
public class ProgThree { public static void main (String[] args) throws Exception {
NXTMotor MA = new NXTMotor(MotorPort.A); NXTMotor MB = new NXTMotor(MotorPort.B); UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);
MA.setPower(100); MB.setPower(100);
while(!(us.getRange() < 20) ) { // 20cm threshold Thread.sleep(200); } MA.stop(); MB.stop(); } }
Modify the program so that after it detects an obstacle, it will stop and then go into reverse for 1 second.
So far our robot has gone forward and backward only. Classes are provided in LEJOS that will do precise turns, but we want to do it from first principles. Basically, to turn right, the left motor goes to full power while the right motor is stopped. Write a program that will move forward for 2 seconds, then do a 90 degree right turn, and then move forward again for 2 seconds. For this, you will have to calibrate how long is required for the turn yourself.
Write a program that will cause your robot to drive in a figure of 8.