Use of a USB-connected potentiometer with Psychopy

Thanks for the tip, Michael. From your suggestion I was able to make it work with an additional code piece that is needed. Initially I could not get the joystick position updated despite having “joystick.get_axis(0)” in the “each frame” tab. By trial and error I found that I needed also “pygame.event.pump()” in order to have the joystick position updated each frame (pygame.event — pygame v2.1.3 documentation), like this:

pygame.event.pump()

joy_x = joystick.get_axis(0)

# presumably you will need to scale this value to use it with a slider,
# e.g. something like:

scaled_joy_x = (joy_x / some_value) * some_slider_max_value

# then apply this value to the slider object to change the current rating value.

Hopefully this will help others who need to update the joystick position in a routine. Cheers.

1 Like