I have a serious problem with my NXT brick.
I built Alpha Rex using the original Lego Software and played with the built-in programs. Then, I tried to convert the built-in Alpha Rex programs to leJOS. While I was working on the program, I put the program on AutoRun; so every time I turn on the NXT, it goes straight to the program.
Below is the source code for this program.
- Code: Select all
/* ~0821 Sunday, June Sixth, Twenty-Ten*/
import lejos.nxt.Button;
import lejos.nxt.ColorLightSensor;
import lejos.nxt.LCD;
import lejos.nxt.Motor;
import lejos.nxt.Sound;
import lejos.nxt.TouchSensor;
import lejos.nxt.UltrasonicSensor;
public class FrthWalk {
int RnTn, RnLn, CmBf, AcPt = 180, RjCt = 241, LpCn; boolean ExIt;
ColorLightSensor HaNd; Motor ArMs = Motor.A, LeFt = Motor.B, RgHt = Motor.C;
Button EnTr = Button.ENTER; TouchSensor LfHl, RgHl; UltrasonicSensor EyEs;
public FrthWalk() {
HaNd = new ColorLightSensor(lejos.nxt.SensorPort.S3, ColorLightSensor.TYPE_COLORFULL); LeFt.setPower(45); RgHt.setPower(45);
LfHl = new TouchSensor(lejos.nxt.SensorPort.S1); RgHl = new TouchSensor(lejos.nxt.SensorPort.S2);
EyEs = new UltrasonicSensor(lejos.nxt.SensorPort.S4); LCD.drawString("Fourth Walk", 2, 0);
}
public static void main(String [] args) {
FrthWalk f = new FrthWalk();
f.Look(); f.Arms(); f.Walk();
f.Please(); f.Dance(); f.Play();
}
void Look() {
LCD.drawString("Looking", 0, 1);
LCD.drawString("No see\t", 0, 2);
do {LCD.drawString(EyEs.getDistance(), 9, 2);} while(EyEs.getDistance() <= 24);
LCD.drawString("I see you! ", 0, 2);
Sound.playTone(250, 23);
}
void Arms() {
LCD.drawString("Arms Bck & Frth", 0, 3);
do {ArMs.rotate(180); ArMs.rotate(-225);} while(!EnTr.isPressed());
LCD.drawString("Move complete", 0, 4);
}
void Walk() {
LCD.drawString("Walking", 0, 5); LeFt.forward(); do {
do {} while(!LfHl.isPressed()); LeFt.rotate(90); RgHt.forward();
do {} while(!RgHl.isPressed()); RgHt.rotate(90); LeFt.forward();
LpCn++;} while(LpCn != 10); LeFt.stop(); RgHt.stop();
}
void Please() {
ArMs.rotateTo(-90); Sound.playTone(261, 50);
LCD.drawString("Please", 0, 6); do {
if (HaNd.readColor().name() == "RED") Red();
else if (HaNd.readColor().name() == "BLUE") Blue();
else if (HaNd.readColor().name() == "BLACK") Black();
else if (HaNd.readColor().name() == "YELLOW") Yellow();
else if (HaNd.readColor().name() == "WHITE") White();
else if (HaNd.readColor().name() == "GREEN") Green();
} while(!ExIt);
}
void Dance() {
LCD.drawString("Dancing", 0, 7); LeFt.rotateTo(0);
RgHt.rotateTo(0); LeFt.forward(); RgHt.forward();
try {Thread.sleep(750);} catch(Exception e) {lejos.nxt.NXT.shutDown();}
LeFt.stop(); RgHt.stop();
}
void Play() {
do {
do {RnTn = ((int)(Math.random() * 150));} while(RnTn < 85);
do {RnLn = ((int)(Math.random() * 750));} while(RnLn < 300);
Sound.playTone(RnTn, RnLn); CmBf++; try {Thread.sleep(RnLn);}
catch(Exception e) {lejos.nxt.NXT.shutDown();}
} while(CmBf != 48);
}
void Red() {Sleep(); LCD.drawString("Red", 0, 6); ArMs.rotate(RjCt); Sound.playTone(9000, 100);}
void Blue() {Sleep(); LCD.drawString("Blue", 0, 6); ArMs.rotate(RjCt); Sound.playTone(6000, 100);}
void Black() {Sleep(); LCD.drawString("Black", 0, 6); ArMs.rotate(RjCt); Sound.playTone(3000, 100);}
void White() {Sleep(); LCD.drawString("White", 0, 6); ArMs.rotate(RjCt); Sound.playTone(0750, 100);}
void Green() {Sleep(); LCD.drawString("Green", 0, 6); ArMs.rotate(AcPt); Sound.playTone(0250, 100); ExIt = true;}
void Yellow() {Sleep(); LCD.drawString("Yellow", 0, 6); ArMs.rotate(RjCt); Sound.playTone(1000, 100);}
void Sleep() {try {Thread.sleep(375);} catch(Exception e) {lejos.nxt.NXT.shutDown();}}
}
However, there was something wrong with the program and it would freeze in the "Please" method.
Every time I turn on the NXT, everything is normal until it gets to this method. Then the NXT freezes and I have not been able to find away to unfreeze, reset the firmware, or prematurely end the program. I have tried using the reset button on the back or turning off the brick, but when I turn it back on, nevertheless, it goes back to my program and freezes again.
PLEASE help me, a replacement NXT would cost approximately USD 144.99! Thanks in advance.
