| Reference | Downloads | Github

Invert Joystick Direction


Hi, I have a task that involves a joystick and uses PsychoPy3, Pyglet and Python 2.7.3 on Mac and I would like the joystick direction to be inverted. Specifically, right now, when the joystick is pulled towards me, the cursor on the screen moves up, instead of down.

Is there code or a setting I can use to reverse this?
This is the code I have for the joystick:


def probe(self,trial):
    clock = core.Clock()
    joysticks = pyglet.input.get_joysticks()
    assert joysticks, 'No joystick device is connected'
    j = joysticks[0] #we are going to name our joystick j
    flipCount = -1
    starttime = clock.getTime()
    while True:
            elapsed = clock.getTime()-starttime
            if elapsed>2.8:
                break #exit out of this loop, because they are out of time  
            j.close() #have to do this for this pyglet joystick to work 
            self.dis.probe.pos = (j.x*700,j.y*700) # this may need to be adjusted for full screen

thank you!


Hi @Brain_Base, have you thought about using Builder to create your experiment? Using the Builder joystick, inverting the y-axis would be simple. You could assign your joystick positions to a cursor created with a text stim (’+’), and modify the y-axis position value of the text stim with [joystick.getX(), joystick.getY() * -1]. Multiplying your axis by -1 inverts the movement.