# Analog joystick on the PyGamer

**URL:** <https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444>\
**Category:** Arcade\
**Created:** [August 14, 2019, 3:46pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444 "2019-08-14T15:46:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [August 14, 2019, 3:46pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/1 "2019-08-14T15:46:52Z")

</div>

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?

BTW, i think there’s a broken link in docs. [dx](https://arcade.makecode.com/reference/controller/dx) is ok on [https://arcade.makecode.com/reference/controller](https://arcade.makecode.com/reference/controller) but [dy](https://arcade.makecode.com/reference/keys/dy) gives an error - note `controller` vs `keys` in URL.

---

<div class="post-metadata">

**Author:** ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)\
**Post date:** [August 14, 2019, 9:45pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/2 "2019-08-14T21:45:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)\
**Post date:** [August 20, 2019, 1:06am UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/3 "2019-08-20T01:06:13Z")

</div>

I started a PR here: [https://github.com/microsoft/pxt-common-packages/pull/934](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:

> **[analog in test](https://arcade.makecode.com/28713-08944-74565-43632)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I guess you could check if the config value is 0, and don’t do the analog read then.

---

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [August 20, 2019, 8:07am UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/4 "2019-08-20T08:07:43Z")

</div>

I put the code onto my PyGamer:

- first center reading -6,3
- left is -512,6
- top is -8,-512
- right is 511,-4
- down is 5,511
- centre is -6,4

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.

---

<div class="post-metadata">

**Author:** ![auxin](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@auxin](https://forum.makecode.com/u/auxin)\
**Post date:** [August 21, 2019, 1:50pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/5 "2019-08-21T13:50:03Z")

</div>

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?

[https://makecode.com/\_EWgf9XHRYErA](https://makecode.com/_EWgf9XHRYErA)

---

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [August 21, 2019, 2:07pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/6 "2019-08-21T14:07:54Z")

</div>

@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.

What form does your crash take? Do you get the frown face and a number? Many of the error codes are listed on [https://arcade.makecode.com/hardware/errors](https://arcade.makecode.com/hardware/errors)

---

<div class="post-metadata">

**Author:** ![mileswatson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mileswatson/32/333_2.png) [@mileswatson](https://forum.makecode.com/u/mileswatson)\
**Post date:** [August 21, 2019, 2:08pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/7 "2019-08-21T14:08:40Z")

</div>

I have:

- Center -18, -29
- Left -512, -40
- Up -29, -512
- Right 511, -40
- Down 511, -20

Up-Left: -420, -473  
Up-Right: 511, -380  
Down-Left: -450, 294  
Down-Right: 511, 320

It would be interesting to see if these values change over time due to components wearing down… ⚠

---

<div class="post-metadata">

**Author:** ![auxin](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@auxin](https://forum.makecode.com/u/auxin)\
**Post date:** [August 21, 2019, 9:42pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/8 "2019-08-21T21:42:12Z")

</div>

My exact values are:  
Center: 11, -10  
Left: -512, -11  
Right: 511, -17  
Up: -3, -512  
Down: 7, 511

Up-Left: -455, -438  
Up-Right: 480, -481  
Down-Left: -445, 440  
Down-Right: 436, 445

When it crashes it is just freezing completely up. I can’t bring up the menu and it doesn’t give the frowny face either.

---

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [March 10, 2020, 12:36am UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/9 "2020-03-10T00:36:15Z")

</div>

BTW, these docs are broken:

- [https://arcade.makecode.com/reference/controller/dy](https://arcade.makecode.com/reference/controller/dy) (this is for dx)
- [https://arcade.makecode.com/reference/keys/dy](https://arcade.makecode.com/reference/keys/dy) (404 - this is the link on [controller](https://arcade.makecode.com/reference/controller) page)

---

<div class="post-metadata">

**Author:** ![slimehunter](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@slimehunter](https://forum.makecode.com/u/slimehunter)\
**Post date:** [September 9, 2020, 2:48pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/10 "2020-09-09T14:48:33Z")

</div>

I’m seeing the same thing.

The documentation page for dy shows the content of dx in it.

When I open the block editor and right-click help on dy, it will point to the page [https://arcade.makecode.com/reference/keys/dy](https://arcade.makecode.com/reference/keys/dy)

---

<div class="post-metadata">

**Author:** ![kwx](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kwx/32/1545_2.png) [@kwx](https://forum.makecode.com/u/kwx)\
**Post date:** [February 26, 2021, 5:54pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/11 "2021-02-26T17:54:23Z")

</div>

> [@auxin](#):
>
> When it crashes it is just freezing completely up. I can’t bring up the menu and it doesn’t give the frowny face either.

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](https://forum.makecode.com/t/space-rocks-3d/6334/33).

---

<div class="post-metadata">

**Author:** ![kwx](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kwx/32/1545_2.png) [@kwx](https://forum.makecode.com/u/kwx)\
**Post date:** [March 18, 2021, 3:20pm UTC](https://forum.makecode.com/t/analog-joystick-on-the-pygamer/444/12 "2021-03-18T15:20:36Z")

</div>

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](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.)
