A better joystick library to handle dual-axis Arduino joysticks.
Better Joystick allows the user to interface with the Arduino joystick component. It provides simple yet useful functions that make sense for a dual-axis joystick.
Better Joystick can be installed through the Library Manager in the Arduino IDE :D.
A simple Joystick
object can be created with the relevant pins in the constructor, like this:
Joystick joystick(A0, A1, 7); // X, Y, switch
The Joystick
class contains many methods that can be called in a similar fashion.
Retrieves the x
position of the joystick
joystick.x()
Retrieves the y
position of the joystick
joystick.y()
Retrieves the x
position after mapping from 0, 1023 to lowerBound
, upperBound
.
Retrieves the y
position after mapping from 0, 1023 to lowerBound
, upperBound
.
Returns 1
if the joystick is pressed and 0
if the joystick is not pressed.
Returns a value from 0 to 1 representing the normalized distance from the joystick's position to the center (512, 512).
Returns an element from the DIRECTION
enum depending on the direction the joystick is facing.
The DIRECTION
enum is defined as follows:
enum DIRECTION {
UP,
RIGHT,
DOWN,
LEFT,
CENTER
};
Better Joystick is released under the GNU General Public License v3.0
Contact me here if you have any suggestions or comments.
Thanks for viewing!