Add support for multiplexers. This introduces a new dependency, but c'est la vie.
This commit is contained in:
parent
da37d16da7
commit
d6e0648abf
3 changed files with 74 additions and 13 deletions
23
Readme.md
23
Readme.md
|
@ -2,17 +2,28 @@
|
|||
This is a library that builds and sends USB HID Joystick reports, making it easy to build USB Joysticks with Arduino.
|
||||
|
||||
## Dependencies
|
||||
* Your Arduino's USB communication chip must be programmed with the arduino-big-joystick firmware (or similar). See <https://github.com/harlequin-tech/arduino-usb> for more info.
|
||||
* 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
|
||||
1. Put the arduino-joystick directory into your Arduino libraries directory.
|
||||
2. Make sure Bounce2 is installed!
|
||||
1. Install dependencies as above, or if using `arduino-cli`, with:
|
||||
arduino-cli lib install Bounce2
|
||||
arduino-cli lib install "Analog-Digital Multiplexers"
|
||||
2. Put the arduino-joystick directory into your Arduino libraries directory.
|
||||
|
||||
## Usage
|
||||
1. In your arduino sketch, add the includes:
|
||||
#include <Bounce2.h>
|
||||
#include <Joystick.h>
|
||||
2. Create a Joystick object:
|
||||
Joystick joystick;
|
||||
3. Add buttons and axes in setup() with Joystick::AddButton(), and call Joystick::Update() in loop(). That's it!
|
||||
Joystick joystick(true);
|
||||
3. Add buttons and axes in setup() with Joystick::AddButton(), and call Joystick::Update() in loop().
|
||||
4. Upload the sketch, connect to the serial monitor (at 115200 baud) and test the buttons.
|
||||
5. Set the joystick's `debug` parameter to `false` and re-upload the sketch. The arduino will NOT work in joystick mode with debug set to `true`!
|
||||
6. Flash the `arduino-big-joystick` firmware onto the USB Controller.
|
||||
|
||||
### Advanced usage: multiplexers
|
||||
|
||||
If you need more buttons than your board has pins, multiplexers (such as [this one](https://www.sparkfun.com/products/13906) and [this one](https://www.sparkfun.com/products/9056)) are a popular solution. This library supports multiplexers! To use them, you need to do some extra work.
|
||||
|
||||
Call the `AddMux()` method and pass it the pins the multiplexer is connected to. It will return a `mux_id` for subsequently passing to `AddButton()`. The `pin` parameter for all multiplexed buttons should be the same as the multiplexer's `signal_pin`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue