Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

Working with joystick and timing out

S_HS_H Posts: 27

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.


Sign In or Register to comment.