Phys/CSci 135: Assignments
Lab 3. Counting Rotations
ShowFinalCounts (page 17)
import lejos.nxt.*;
public class ShowFinalCounts {
public static void main(String[] args) {
Motor.B.forward();
Motor.C.forward();
while (Button.LEFT.isPressed() == false ) {
}
Motor.B.stop();
Motor.C.stop();
LCD.drawString("Left " + Motor.B.getTachoCount(), 0 , 0 );
LCD.drawString("Right " + Motor.C.getTachoCount(), 0 , 1 );
while (Button.ESCAPE.isPressed() == false ) {}
}
}
DriveDistance (page 21)
import lejos.nxt.*;
public class DriveDistance {
public static void main(String[] args) {
Motor.B.forward();
Motor.C.forward();
while (Motor.B.getTachoCount() > 180 ) {
}
Motor.B.stop();
Motor.C.stop();
}
}
DriveAndTurn (page 24)
import lejos.nxt.*;
public class DriveAndTurn {
public static void main(String[] args) {
Motor.B.forward();
Motor.C.forward();
while (Motor.B.getTachoCount() < 300 ) {}
Motor.C.stop();
while (Motor.C.getTachoCount() < 250 ) {}
}
}