Added all remaining gists.
This commit is contained in:
120
MotorTest.java/MotorTest.java
Normal file
120
MotorTest.java/MotorTest.java
Normal file
@@ -0,0 +1,120 @@
|
||||
import lejos.nxt.Button;
|
||||
import lejos.nxt.LCD;
|
||||
import lejos.nxt.Motor;
|
||||
|
||||
public class MotorTest{
|
||||
private static final int MAX_CHOICES = 8;
|
||||
private static final int MAX_ROTATION_DEGREES = 3600;
|
||||
|
||||
public static void main(String[] args){
|
||||
boolean done = false;
|
||||
int choice = 0;
|
||||
|
||||
printMenu(choice);
|
||||
|
||||
while(!done){
|
||||
switch(Button.waitForAnyPress()){
|
||||
case Button.ID_ENTER:
|
||||
startMotors(choice);
|
||||
break;
|
||||
|
||||
case Button.ID_LEFT:
|
||||
choice = (choice - 1 < 0) ? MAX_CHOICES - 1 : choice - 1;
|
||||
break;
|
||||
|
||||
case Button.ID_RIGHT:
|
||||
choice = (choice + 1) % MAX_CHOICES;
|
||||
break;
|
||||
|
||||
default:
|
||||
case Button.ID_ESCAPE:
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
|
||||
printMenu(choice);
|
||||
}
|
||||
}
|
||||
|
||||
private static void printMenu(int choice){
|
||||
LCD.clear();
|
||||
LCD.drawString("Motors:", 0, 0);
|
||||
printMotorChoiceLine(choice);
|
||||
LCD.drawString("ENTER: EXEC", 0, 2);
|
||||
LCD.drawString("ESC: QUIT", 0, 3);
|
||||
}
|
||||
|
||||
private static void startMotors(final int choice){
|
||||
Motor.A.stop(true);
|
||||
Motor.B.stop(true);
|
||||
Motor.C.stop(true);
|
||||
|
||||
switch(choice){
|
||||
case 0:
|
||||
Motor.A.rotate(MAX_ROTATION_DEGREES, true);
|
||||
Motor.B.rotate(MAX_ROTATION_DEGREES, true);
|
||||
Motor.C.rotate(MAX_ROTATION_DEGREES, true);
|
||||
break;
|
||||
case 1:
|
||||
Motor.A.rotate(MAX_ROTATION_DEGREES, true);
|
||||
Motor.B.rotate(MAX_ROTATION_DEGREES, true);
|
||||
break;
|
||||
case 2:
|
||||
Motor.B.rotate(MAX_ROTATION_DEGREES, true);
|
||||
Motor.C.rotate(MAX_ROTATION_DEGREES, true);
|
||||
break;
|
||||
case 3:
|
||||
Motor.A.rotate(MAX_ROTATION_DEGREES, true);
|
||||
Motor.C.rotate(MAX_ROTATION_DEGREES, true);
|
||||
break;
|
||||
case 4:
|
||||
Motor.A.rotate(MAX_ROTATION_DEGREES, true);
|
||||
break;
|
||||
case 5:
|
||||
Motor.B.rotate(MAX_ROTATION_DEGREES, true);
|
||||
break;
|
||||
case 6:
|
||||
Motor.C.rotate(MAX_ROTATION_DEGREES, true);
|
||||
break;
|
||||
case 7:
|
||||
Motor.A.stop(true);
|
||||
Motor.B.stop(true);
|
||||
Motor.C.stop(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void printMotorChoiceLine(final int choice){
|
||||
switch(choice){
|
||||
case 0:
|
||||
LCD.drawString("A - B - C", 0, 1);
|
||||
break;
|
||||
case 1:
|
||||
LCD.drawString("A - B", 0, 1);
|
||||
break;
|
||||
case 2:
|
||||
LCD.drawString("B - C", 0, 1);
|
||||
break;
|
||||
case 3:
|
||||
LCD.drawString("A - C", 0, 1);
|
||||
break;
|
||||
case 4:
|
||||
LCD.drawString("A", 0, 1);
|
||||
break;
|
||||
case 5:
|
||||
LCD.drawString("B", 0, 1);
|
||||
break;
|
||||
case 6:
|
||||
LCD.drawString("C", 0, 1);
|
||||
break;
|
||||
case 7:
|
||||
LCD.drawString("STOP ALL", 0, 1);
|
||||
break;
|
||||
default:
|
||||
LCD.drawString("INVALID", 0, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
MotorTest.java/README.md
Normal file
1
MotorTest.java/README.md
Normal file
@@ -0,0 +1 @@
|
||||
A LejOS application to start/stop the motors of a LEGO Mindstorms NXT.
|
||||
Reference in New Issue
Block a user