Introduction
A joystick is an input device used to control the movement or actions of a computer, video game console, or other electronic device. In gaming, joysticks are often used to control the movement of characters or vehicles in a virtual environment. They provide analog input, meaning the degree of movement can vary based on how far the handle is pushed in a particular direction. In aviation and flight simulation, joysticks are commonly used to simulate the control of aircraft, providing pitch, roll, and yaw inputs. Some advanced joysticks also come with additional features such as throttle controls, programmable buttons, and force feedback to enhance the gaming or simulation experience. below is a simple animation of a joystick.
In this example, we’ll be interfacing a joystick with Quarky and try to read the values of the joystick along the x and y axis let’s begin!!
Circuit Diagram
connection
JoyStick Quarky
GND GND
5V V
VarX A1
VarY A2
Code
- Connect JoyStick as per the above connections.
- Open pictoblx and create a new file.
- Select Quarky from the board menu.
- From events palette drag when the” flag clicked “block into the scripting area.
- Now add a “forever ” loop from controls palette
- A say() block from the looks palette
- from the sensor palette of Quarky add “read analog sensor () at pin()” in place of hello. and select “joystick X” at pin A1 from the dropdown.
Now run the code, with this simple script, you will be able to read the value of the joystick along for X-axis in forward, backward, left, and right. with these values you will be able to set the logic on different values for fixing the direction as forward, backward, etc. do same for finding values for Y-axis.
Task for you.
Try to print the value of both the axis together