Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
đ Ready to explore and create with us? Click [here] and join today!
4.1 Toggle the Joystickï
If you play a lot of video games, then you should be very familiar with the Joystick. It is usually used to move the character around, rotate the screen, etc.
The principle behind Joystickâs ability to allow the computer to read our actions is very simple. It can be thought of as consisting of two potentiometers that are perpendicular to each other. These two potentiometers measure the analog value of the joystick vertically and horizontally, resulting in a value (x,y) in a planar right-angle coordinate system.
The joystick of this kit also has a digital input, which is activated when the joystick is pressed.
Required Components
In this project, we need the following components.
Itâs definitely convenient to buy a whole kit, hereâs the link:
Name |
ITEMS IN THIS KIT |
LINK |
|---|---|---|
Kepler Kit |
450+ |
You can also buy them separately from the links below.
SN |
COMPONENT |
QUANTITY |
LINK |
|---|---|---|---|
1 |
1 |
||
2 |
Micro USB Cable |
1 |
|
3 |
1 |
||
4 |
Several |
||
5 |
1(10KΩ) |
||
6 |
1 |
Schematic

The SW pin is connected to a 10K pull-up resistor, the reason is to be able to get a stable high level on the SW pin (Z axis) when the joystick is not pressed; otherwise the SW is in a suspended state and the output value may vary between 0/1.
Wiring

Code
Note
Open the
4.1_toggle_the_joystick.pyfile under the path ofkepler-kit-main/micropythonor copy this code into Thonny, then click âRun Current Scriptâ or simply press F5 to run it.Donât forget to click on the âMicroPython (Raspberry Pi Pico)â interpreter in the bottom right corner.
For detailed tutorials, please refer to Open and Run Code Directly.
import machine
import utime
x_joystick = machine.ADC(27)
y_joystick = machine.ADC(26)
z_switch = machine.Pin(22,machine.Pin.IN)
while True:
x_value = x_joystick.read_u16()
y_value = y_joystick.read_u16()
z_value = z_switch.value()
print(x_value,y_value,z_value)
utime.sleep_ms(200)
After the program runs, the Shell prints out the x,y,z values of joystick.
The x-axis and y-axis values are analog values that vary from 0 to 65535.
The Z-axis is a digital value with a status of 1 or 0.