Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Working with joystick and timing out

Hello everyone,

I am trying to write a code in an inline_script code that suppose to work with a joystick I have.

I want 'up' response to be stored as 'o', 'down ' response as 'b' and to quit if no response is given after 2 seconds.

That's what I have by now:

    t0 = clock.time()  
    NowPoint = joystick.get_joyaxes(timeout=None)       #Collect initial position of the joystick

    Baseline = NowPoint[0][1]                           #Define the Y axis baseline

    stop = False                                        

    var.response = 'None'                               #if no response is taken, so it'll be None anyway

    while not stop:

        Current = joystick.get_joyaxes(timeout=None)    #Get current position
        Value = Current[0][1]                           #get the Y axis
        Now = self.time()                               #What time is it?
        if Now-t0>2000:                             #Is it Timeout time?

        if Baseline + abs(Value) > 0.1:                 #Compare position to baseline
            var.RT = self.time() - t0               #Measure RT
            if Value <0:                                
                var.response = 'o'                                  
            if Value > 0:                               
                var.response = 'b'                      


The problem is that the 'Timeout' is highly varied and could reach to up to 2600 msec! that's 600 msec after what I need.

I will be grateful for any tips making the timeout (or the code in general) more accurate.


  • Somone? please?

  • Hi,

    If you set Current = joystick.get_joyaxes(timeout=None) to Current = joystick.get_joyaxes(timeout=0) does the problem persist?

    Also your t0 is rather far away from the loop. that causes unnecessary delay. You should define it , right before entering the while loop.

    Hope this solves it.


  • Yes! Thanks!

Sign In or Register to comment.