Timer Help

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

Moderator: roger

New User
Posts: 1
Joined: Sat Aug 18, 2007 4:22 am

Timer Help

Postby Bonzol » Sun Aug 19, 2007 7:14 am


I am having trouble using a timer. In my program the robot is ment to follow a wall and when it loses the wall it spins around in circles in a loop trying to

find the wall again. However , sometimes it does not find the wall again and will keep spinning around indefinetely! So what I want do is put a timer on this

loop which will break out of the loop after 5 seconds. So what I have done is this.

class Robot implements TimerListener
private static boolean breakOut = true;
private static Sensor lightSensor3 = Sensor.S3;
public void timedOut()
breakOut = false;

public static void goLeftWithSensor()
Timer timer = new Timer(5000, new Robot());
while (lightSensor3.readValue() < 33 && breakOut)

This class is called in the sensor listner every time the value is below 33 and then this class will keep the robot in the while loop untill the sensor

value is greater then 33. So this class will be called a lot. However, I only want to do this for 5 seconds. This works correctly, but say if it breaks out

of the while loop before the timer is up, it will still activate the timedOut() method.

So my question is, how to make it so the timedOut method is ONLY accessed when the timer reaches 5 seconds, not before even if the loop is broken out of and

the program keeps going.

Also, is it possible to detect if a wheel is jammed and not moving? so I can make it revearse.

Thanks in advance!

New User
Posts: 22
Joined: Sun Aug 12, 2007 2:22 am

Postby jvance » Wed Sep 12, 2007 1:05 am

I can't answer with your first question, but maybe I can help with the second
Possibly Motor.isMoving() can help you or

boolean isBackward()
Return true if motor is backward.

boolean isFloating()

boolean isForward()
Return true if motor is forward.

boolean isStopped()

maybe these methods can help. All of them are in the Motor class

Return to “RCX Software”

Who is online

Users browsing this forum: No registered users and 0 guests