[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] How to do some action while a joystick is in motion?



I'm making a controller for a PTZ ("pan/tilt/zoom") camera using Pygame, so I can move the camera around with a gaming joystick. It works but the motion is very jerky.

The camera expects a "start" action ("start moving the camera left") and then a stop action ("stop moving it"). I'm handling that by sending a start motion command when the joystick is up, then a pause, and then a stop motion command. So the motion happens in jerky pulses.

Is there some best practice for doing my action WHILE the joystick is in a certain position? If I can send a "start motion" command when the joystick moves up, and then the "stop motion" command when the joystick is centered, the motion would be smooth. But all the code samples I've seen poll the joystick and then act on the joystick states.

I posted my code here if anyone wants to have a look:

boofadmin.com/dropbox/camera_joystick.zip

Or maybe there's a code sample that illustrates the best practice of reading joystick states?

Thanks for any help!