Compare commits
2 Commits
a9c80c2ed5
...
557aec4644
Author | SHA1 | Date | |
---|---|---|---|
557aec4644 | |||
2ce994677a |
17
Joystick.h
17
Joystick.h
|
@ -33,14 +33,19 @@ class Joystick {
|
||||||
void Init();
|
void Init();
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
// Add a button to the joystick.
|
// Use these functions to add a button to the joystick.
|
||||||
// Button types are documented in the ButtonType enum.
|
// Button types are documented in the ButtonType enum. See Button.h for details.
|
||||||
// If `pullup` is true, your button should connect the pin to ground. (also be sure that your board supports INPUT_PULLUP on that pin)
|
// If 'pullup' is true, your button should connect the pin to ground. (also be sure that your board supports INPUT_PULLUP on that pin)
|
||||||
// If `pullup` is false, your button should connect the pin to VCC.
|
// If 'pullup' is false, your button should connect the pin to VCC.
|
||||||
// Setting `analogOnly` to true indicates your button *must* be read with analog code, such as the A6 and A7 pins
|
|
||||||
// on the Arduino Nano.
|
// Add a button connected directly to a pin on the microcontroller.
|
||||||
void AddButton(uint8_t pin, ButtonType type, bool pullup=true);
|
void AddButton(uint8_t pin, ButtonType type, bool pullup=true);
|
||||||
|
|
||||||
|
// Add a button connected to a channel on a Multiplexer.
|
||||||
|
// FIXME: This doesn't currently work!
|
||||||
void AddMuxButton(uint8_t channel, Mux* mux, ButtonType type, bool pullup=true);
|
void AddMuxButton(uint8_t channel, Mux* mux, ButtonType type, bool pullup=true);
|
||||||
|
|
||||||
|
// Add a button connected to a scan matrix.
|
||||||
void AddMatrixButton(uint8_t row, uint8_t col, Matrix* matrix, ButtonType type, bool pullup=true);
|
void AddMatrixButton(uint8_t row, uint8_t col, Matrix* matrix, ButtonType type, bool pullup=true);
|
||||||
|
|
||||||
// Add a rotary encoder. ENCODER button types allow you to treat an encoder as a momentary button or an axis (TODO)
|
// Add a rotary encoder. ENCODER button types allow you to treat an encoder as a momentary button or an axis (TODO)
|
||||||
|
|
|
@ -19,7 +19,7 @@ uint8_t Reader::getMode(bool pullup) {
|
||||||
|
|
||||||
DirectReader::DirectReader(uint8_t pin, bool inverted) : Reader(inverted) {
|
DirectReader::DirectReader(uint8_t pin, bool inverted) : Reader(inverted) {
|
||||||
uint8_t mode = getMode(inverted);
|
uint8_t mode = getMode(inverted);
|
||||||
this->bouncer.attach(pin);
|
this->bouncer.attach(pin, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirectReader::Update() {
|
bool DirectReader::Update() {
|
||||||
|
|
16
Readme.md
16
Readme.md
|
@ -12,18 +12,22 @@ This is a library that builds and sends USB HID Joystick reports, making it easy
|
||||||
arduino-cli lib install "Analog-Digital Multiplexers"
|
arduino-cli lib install "Analog-Digital Multiplexers"
|
||||||
2. Put the arduino-joystick directory into your Arduino libraries directory.
|
2. Put the arduino-joystick directory into your Arduino libraries directory.
|
||||||
|
|
||||||
|
## Compiling and running the example code via SimulIDE
|
||||||
|
1. Run `make` from the `example` directory.
|
||||||
|
2. Load `example.simu` in SimulIDE.
|
||||||
|
3. Right-click on the Arduino component, and click "load firmware". Select the `.hex` file created in the `example/` directory.
|
||||||
|
4. Click the red `Power Circuit` icon at the top of the SimulIDE window.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
1. In your arduino sketch, add the includes:
|
1. In your arduino sketch, add the include:
|
||||||
#include <Joystick.h>
|
#include <Joystick.h>
|
||||||
2. Create a Joystick object:
|
2. Create a Joystick object:
|
||||||
Joystick joystick(true);
|
Joystick joystick(true);
|
||||||
3. Add buttons and axes in setup() with Joystick::AddButton(), and call Joystick::Update() in loop().
|
3. Add buttons and axes in `setup()` with the `Add*` functions from `Joystick.h`. Call `joystick.Update()` in your `loop()` function. Also call `joystick.Init()` during `setup()`.
|
||||||
4. Upload the sketch, connect to the serial monitor (at 115200 baud) and test the buttons.
|
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`!
|
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.
|
6. Flash the `arduino-big-joystick` firmware onto the USB Controller.
|
||||||
|
|
||||||
### Advanced usage: multiplexers
|
### Advanced usage: multiplexers, matrices
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
Call the `AddMux()` method and pass it the pins the multiplexer is connected to. You'll need to `#include <Mux.h>` to access `admux::Pinset`. `AddMux()` 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`.
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ using namespace admux;
|
||||||
#define BTN2 5
|
#define BTN2 5
|
||||||
#define BTN3 6
|
#define BTN3 6
|
||||||
#define BTN4 7
|
#define BTN4 7
|
||||||
|
#define BTN5 A0
|
||||||
|
|
||||||
// pins 8-13 are attached to a 3x3 scanning input matrix. Pins 8-10 are the row pins, 11-13 are the column pins.
|
// pins 8-13 are attached to a 3x3 scanning input matrix. Pins 8-10 are the row pins, 11-13 are the column pins.
|
||||||
#define MATRIX1 8,11
|
#define MATRIX1 8,11
|
||||||
|
@ -69,6 +70,9 @@ void setup() {
|
||||||
// One press will "press and hold" the button. The next press releases the button.
|
// One press will "press and hold" the button. The next press releases the button.
|
||||||
js.AddButton(BTN4, BUTTON_LATCHED_MOMENTARY);
|
js.AddButton(BTN4, BUTTON_LATCHED_MOMENTARY);
|
||||||
|
|
||||||
|
// This is a standard PASSTHRU button. It simply mirrors the actual state of the physical button.
|
||||||
|
js.AddButton(BTN5, BUTTON_PASSTHRU);
|
||||||
|
|
||||||
// One way to get more room for inputs is to use a scan matrix.
|
// One way to get more room for inputs is to use a scan matrix.
|
||||||
// See http://blog.komar.be/how-to-make-a-keyboard-the-matrix/ for a very detailed discussion of how these work.
|
// See http://blog.komar.be/how-to-make-a-keyboard-the-matrix/ for a very detailed discussion of how these work.
|
||||||
// This is a 3x3 example, so we can get 9 buttons out of 6 inputs.
|
// This is a 3x3 example, so we can get 9 buttons out of 6 inputs.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user