From 2ce994677a08457c04e19cc5ca9c689f8c589408 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Wed, 24 Nov 2021 05:57:41 +0000 Subject: [PATCH] Another bugfix, improve header documentation a bit. --- Joystick.h | 17 +++++++++++------ Reader.cpp | 2 +- example/example.ino | 4 ++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Joystick.h b/Joystick.h index 93cb8e7..e8c5710 100644 --- a/Joystick.h +++ b/Joystick.h @@ -33,14 +33,19 @@ class Joystick { void Init(); void Update(); - // Add a button to the joystick. - // Button types are documented in the ButtonType enum. - // 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. - // Setting `analogOnly` to true indicates your button *must* be read with analog code, such as the A6 and A7 pins - // on the Arduino Nano. + // Use these functions to add a button to the joystick. + // 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 false, your button should connect the pin to VCC. + + // Add a button connected directly to a pin on the microcontroller. 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); + + // Add a button connected to a scan matrix. 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) diff --git a/Reader.cpp b/Reader.cpp index 9bebeba..16df0ec 100644 --- a/Reader.cpp +++ b/Reader.cpp @@ -19,7 +19,7 @@ uint8_t Reader::getMode(bool pullup) { DirectReader::DirectReader(uint8_t pin, bool inverted) : Reader(inverted) { uint8_t mode = getMode(inverted); - this->bouncer.attach(pin); + this->bouncer.attach(pin, mode); } bool DirectReader::Update() { diff --git a/example/example.ino b/example/example.ino index 117e8af..8992979 100644 --- a/example/example.ino +++ b/example/example.ino @@ -18,6 +18,7 @@ using namespace admux; #define BTN2 5 #define BTN3 6 #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. #define MATRIX1 8,11 @@ -68,6 +69,9 @@ void setup() { // BUTTON_LATCHED_MOMENTARY lets you turn a momentary pushbutton into a toggle switch. // One press will "press and hold" the button. The next press releases the button. 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. // See http://blog.komar.be/how-to-make-a-keyboard-the-matrix/ for a very detailed discussion of how these work.