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 , robotics, and various applications. XY Joysticks have three inputs: X axis analogue input for the horizontal axis (), Y axis analogue input for the vertical axis (), and a digital push button input ().
To wire up your XY joystick, you need to connect: GND to GND on the Microbit Breakout board, +5V to +5V on the Microbit Breakout Board, VRX to Pin 0 on the Microbit (or other pin), VRY to Pin 1 on the Microbit (or other pin), and SW to Pin on the Microbit. The joystick provides two axes of movement: horizontal and vertical, with a range of values that can be read by the Microbit, facilitating actions based on input.
To read the joystick input, you typically use the function on the specified pins connected to the joystick. This reads in an value from 0 to 1023. The two analogue inputs from pin 0 and pin 1 provide values between 0 and 1023, but 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 and returning a whole number. This can be achieved easily using the block. Reading the push button input can be accomplished through digital read for the SW signal on pin 8.