Bug in less than operator

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, imaqine, 99jonathan

jugendforscht
New User
Posts: 4
Joined: Thu Dec 01, 2011 7:33 am

Bug in less than operator

Postby jugendforscht » Thu Dec 01, 2011 7:57 am

I have a problem with the less than operator.

Source:
Ultrasonicsensor senor = new Ultrasonicsensor(SensorPort.S4);
int number = 500, currentDistance = 1;
boolean continueLoop = true;
do
{
currentDistance = sensor.getDistance;
continueLoop = currentDistance < number;
}
while (continueLoop);
Sound.beep();

So you should hear a sound, if currentDistance is greater than 500.
But the loop just continues. I tried other posisbilities with if-then and also ? :.
But it just doesn't work. I think it is probably a problem with the less than operator.

Do you have this problem too? Do you know how to solve it?
Marco

P.S. I'm german. So my English isn't perfect.

skoehler
leJOS Team Member
Posts: 1484
Joined: Thu Oct 30, 2008 4:54 pm

Re: Bug in less than operator

Postby skoehler » Thu Dec 01, 2011 10:17 am

currentDistance will NEVER be larger than 255. That's the value the UltraSonic returns if no object is found in front of it.
That you never hear a beep is actually correct.

jugendforscht
New User
Posts: 4
Joined: Thu Dec 01, 2011 7:33 am

Re: Bug in less than operator

Postby jugendforscht » Thu Dec 01, 2011 7:10 pm

But I moved the sensor in front of a wall and let the sensorvalue display. So I saw the value and with enough distance from the wall it was between 550 and 700. But the loop doesn't exit.

Marco

skoehler
leJOS Team Member
Posts: 1484
Joined: Thu Oct 30, 2008 4:54 pm

Re: Bug in less than operator

Postby skoehler » Thu Dec 01, 2011 7:15 pm

jugendforscht wrote:But I moved the sensor in front of a wall and let the sensorvalue display. So I saw the value and with enough distance from the wall it was between 550 and 700. But the loop doesn't exit.

I believe, you were drawing on the LCD without clearing it first. Hence, you see high 3 digit numbers. Imagine you first draw 255 and then 30 without clearing it first. That results is "305" on the display because the "5" from the 255 remains visible.

jugendforscht
New User
Posts: 4
Joined: Thu Dec 01, 2011 7:33 am

Re: Bug in less than operator

Postby jugendforscht » Fri Dec 02, 2011 6:44 pm

Thank you! I'm sure that this was the problem. I will try this tomorrow. I think it will work then.

Marco

jugendforscht
New User
Posts: 4
Joined: Thu Dec 01, 2011 7:33 am

Re: Bug in less than operator

Postby jugendforscht » Sat Dec 03, 2011 12:14 pm

Yesss! It works! Thank you very much! :D :D :D


Return to “NXJ Software”

Who is online

Users browsing this forum: Baidu [Spider], Yahoo [Bot] and 3 guests