# Sugar Joystick Module

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/joy1.png)

This is a joystick module in the Sugar sensor series, it can detect joystick positions and trigger status. The pin holes on the back allow compatibility with plastic building blocks.

### Product Specifications

* Dimensions: 24 x 24 x 23 mm
* Weight: 7g
* Type: I2C
  * X: -255\~255
  * Y: -255\~255
  * Button: 0\~1

### Wiring

Use a 4Pin cable to connect the module to the 4Pin I2C Port on the Robotbit Edu.

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/joy_wire.png)

### Programming Tutorial

### MakeCode Programming Tutorial

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/mcbanner.png)

#### Import Sugar Extension

#### Search for sugar in the search bar (Kittenbot products has been verified by Microsoft)

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/sugar_search.png)

#### Extension URL

Sugar extension: <https://github.com/KittenBot/pxt-sugar>

[Importing Extensions Tutorial](/programming-platforms/makecode-tutorial/kittenbot-and-makecode.md)

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/joy_mc_code.png)

[Sample Program](https://makecode.microbit.org/_hzo7aFVv58jL)

#### Kittenblock Programming Tutorial

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/kbbanner.png)

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/joy3.png)

#### MicroPython Programming Tutorial

```
JoyStick()
value(dir)
state()
```

* dir: X/Y
* state(): Returns none when trigger is not pressed, returns pressed/left/right/up/down when pressed.

Sample Program

```
from future import *
from sugar import *

joystick = JoyStick()
screen.sync = 0

while True:
    screen.fill((0, 0, 0))
    screen.text(str("X: ")+str(joystick.value('x')), x = 5, y = 10)
    screen.text(str("Y: ")+str(joystick.value('y')), x = 5, y = 30)
    if joystick.state() == 'pressed':
        screen.text("Pressed", x = 5, y = 50)
    screen.refresh()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sharinghub-eng.kittenbot.hk/functional_module/sugar/joystick.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
