How do I read the analogue position for the joystick on the PyGamer? I’ve just done a quick test of dx and dy. These looked promising but testing so far (on the default scaling of 100) shows 0 in the middle (good), far left shows -2.2, -2.1, -2 and occasionally -2.3 (reasonable), half way to left is 0 (not so good). Is dx supposed to give an analogue value? Is this just an overly large deadzone? If so, should that zone be smaller and (less important) is it configurable? Or is there another way to read the analogue joystick? That hardware feature looks unique to the PyGamer at the moment?
The joystick is currently treated as digital with a hard coded dead zone. It would be good to fix dx/dy to be analog though. Or maybe introduce a new api. The current dx/dy are just scaled by frame time.
I started a PR here: https://github.com/microsoft/pxt-common-packages/pull/934 but it’s far from complete. It would be useful to get a few data points on what you see when the joystick is idle with the program attached there. I’m thinking dead zone of -50 to 50.
If you want to do something right now, you can use this program, though it will fail in the simulator:
I guess you could check if the config value is 0, and don’t do the analog read then.
I was pushing the joystick around carefully but not being super precise. I thought I’d try the diagonals, the values aren’t what I expected, I thought they would all go to magnitude 512:
top left, -373,-409
top right 412,-467
bottom right 422,441
bottom left -341, 395
Feeling the joystick at its outer range there is a circular range of travel rather than square so this does make sense.
I’m seeing similar numbers to kjw when I test it on my PyGamer. I made some tweaks to the code, but for some reason it crashes after a seemingly random amount of time. Anything obvious that I’m doing wrong that could cause the crash?
@auxin It would be interesting if you could post your actual numbers. These are important to inform a decision on ranges to encompass hardware variation and user variation. The latter may be significant on the diagonals.
I sometimes got apparent hangs on a PyGamer also when trying to use the “analog in test” program, the numbers simply stopped updating. This is inconsistent, just now it failed the first time I tried it, but then hasn’t hung again for the next several attempts.
Here’s my numbers:
center: ranges around -10 to 2,14 to 17
… and now it hung again as I tried to get readings.
Is there anything we can do to diagnose this or to help get this working more reliably? I’d love to add analog joystick controls to Space Rocks 3D.
FYI, there’s a .pressureLevel() property on directional inputs that’s available after setting controller.player1.analog = true. See https://github.com/microsoft/pxt-common-packages/pull/934 for an example. I’ve tried this in Space Rocks 3D and it seems to be working great, I haven’t had it hang so far.
(I’m updating this thread since it seems to be a top result for the topic, and the feature seems to be a bit hard to find.)