Joystick HID API for Arduino.
example | ||
.gitignore | ||
Button.cpp | ||
Button.h | ||
Joystick.cpp | ||
Joystick.h | ||
Matrix.cpp | ||
Matrix.h | ||
Reader.cpp | ||
Reader.h | ||
Readme.md |
Arduino Joystick library
This is a library that builds and sends USB HID Joystick reports, making it easy to build USB Joysticks with Arduino.
Dependencies
- After uploading your sketch, your Arduino's USB communication chip will need to be programmed with the arduino-big-joystick firmware (or similar). See https://github.com/harlequin-tech/arduino-usb for more info.
- The Bounce2 library, available at https://github.com/thomasfredericks/Bounce2.
- The Analog-Digital Multiplexers library, available at https://github.com/stechio/arduino-ad-mux-lib.
Installation
- Install dependencies as above, or if using
arduino-cli
, with: arduino-cli lib install Bounce2 arduino-cli lib install "Analog-Digital Multiplexers" - Put the arduino-joystick directory into your Arduino libraries directory.
Compiling and running the example code via SimulIDE
- Run
make
from theexample
directory. - Load
example.simu
in SimulIDE. - Right-click on the Arduino component, and click "load firmware". Select the
.hex
file created in theexample/
directory. - Click the red
Power Circuit
icon at the top of the SimulIDE window.
Usage
- In your arduino sketch, add the include: #include <Joystick.h>
- Create a Joystick object: Joystick joystick(true);
- Add buttons and axes in
setup()
with theAdd*
functions fromJoystick.h
. Calljoystick.Update()
in yourloop()
function. Also calljoystick.Init()
duringsetup()
. - Upload the sketch, connect to the serial monitor (at 115200 baud) and test the buttons.
- Set the joystick's
debug
parameter tofalse
and re-upload the sketch. The arduino will NOT work in joystick mode with debug set totrue
! - Flash the
arduino-big-joystick
firmware onto the USB Controller.
Advanced usage: multiplexers, matrices
If you need more buttons than your board has pins, this library supports keyboard-style scan matrices as well as multiplexers. (FIXME: multiplexers aren't working yet) See the example sketch in the example/
directory for usage details. Note that, for matrices, the rows are the inputs that will be read, and the columns are the outputs that will sink the current. Current should flow (via diodes) from the rows to the columns. See the example.simu
SimulIDE file for an example circuit.