XY joysticks are essential input devices that allow users to control movement in two dimensions: the X-axis (horizontal) and Y-axis (vertical). These devices are widely used in gaming, robotics, and various interactive applications.
XY Joticks have 3 inputs:
What does the X-axis control in an XY joystick?
To wire up your XY joystick you need to connect:
What is the purpose of connecting GND on the XY joystick to GND on the microbit Breakout board?
The joystick provides two axes of movement: horizontal and vertical. Each axis has a range of values that can be read by the Microbit, facilitating actions based on user input.
To read the joystick input, you typically use the `analogRead` function on the specified pins connected to the joystick. This reads in an analogue value from 0 to 1023.
What is the range of values that the joystick can output when using `analogRead`?
The two analogue inputs from pin 0 and pin 1 provide values between 0 and 1023 but in order to plot these positions on the Microbit's 5x5 grid we need to convert the values from a range of 0 to 1023 to 0 to 4 (effectively dividing each value by 256 and returning a whole number)
This can be achieved easily using the map block.
What is the mathematical operation used to convert the analogue input values from 0-1023 to 0-4?
Reading the push button input can be achieved through digital read for the SW signal on pin 8