Phys/CSci 135: Assignments
Home Syllabus Assignments Samples

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(), 00);
        LCD.drawString("Right " + Motor.C.getTachoCount(), 01);
        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) {}
    }
}