Add rotary encoder support, simplify AddMuxButton interface.

This commit is contained in:
2021-11-07 22:49:14 +00:00
parent 564f4b2b57
commit 09043919de
5 changed files with 106 additions and 15 deletions

8
examples/full/Makefile Normal file
View File

@ -0,0 +1,8 @@
TARGET_BOARD=arduino:avr:uno
COM_PORT=/dev/ttyACM0
build:
arduino-cli compile -b ${TARGET_BOARD}
upload:
arduino-cli upload -b ${TARGET_BOARD} -p ${COM_PORT}

38
examples/full/full.ino Normal file
View File

@ -0,0 +1,38 @@
// An example sketch using the joystick library.
// This example includes every possible feature of the library.
// It assumes an Arduino Nano and a 16-channel multiplexer.
#include <Joystick.h>
#include <Mux.h>
using admux::Pinset;
bool debug = false;
Joystick joystick(debug);
void setup() {
joystick.AddButton(2, BUTTON_PASSTHRU); // this button will always transfer its current literal state to the computer
joystick.AddButton(3, BUTTON_LATCHED_MOMENTARY); // this button will start sending a buttonpress on one push, and keep it "held down" until it is pushed again.
joystick.AddButton(4, BUTTON_PULSED); // this button will send a buttonpress very briefly every time it is activated. Good for a toggle switch that shouldn't be "latched" in practice.
joystick.AddButton(5, BUTTON_PULSED_DOUBLE_ACTION); // like the above, but it sends its button press when toggled on *and* when toggled off
joystick.AddButton(6, BUTTON_PULSED_DOUBLE_ACTION_SPLIT); // again, similar to the above, but it sends two *different* button presses - 'on' will be one button, 'off' another.
joystick.AddEncoder(7, 8, ENCODER_PULSED_SPLIT); // a rotary encoder that will send 2 different buttonpresses - one when the encoder is turned clockwise, another when it is turned counterclockwise.
Pinset addr_pins = Pinset(10, 11, 12, 13);
uint8_t mux_id = joystick.AddMux(9, addr_pins);
joystick.AddMuxButton(mux_id, 0, BUTTON_PASSTHRU);
// start up serial communication
joystick.Init();
}
void loop() {
// check all the button states and send any changes
joystick.Update();
}

View File

@ -32,14 +32,14 @@ void setup() {
uint8_t mux = joystick.AddMux(A1, admux::Pinset(A2, A3, A4, A5), 4);
// now we can add the rest of the buttons
joystick.AddMuxButton(A1, mux, 0, BUTTON_PASSTHRU);
joystick.AddMuxButton(A1, mux, 1, BUTTON_PASSTHRU);
joystick.AddMuxButton(A1, mux, 2, BUTTON_PASSTHRU);
joystick.AddMuxButton(A1, mux, 3, BUTTON_PASSTHRU);
joystick.AddMuxButton(A1, mux, 4, BUTTON_PASSTHRU);
joystick.AddMuxButton(A1, mux, 5, BUTTON_PASSTHRU);
joystick.AddMuxButton(A1, mux, 6, BUTTON_PASSTHRU);
joystick.AddMuxButton(A1, mux, 7, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 0, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 1, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 2, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 3, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 4, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 5, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 6, BUTTON_PASSTHRU);
joystick.AddMuxButton(mux, 7, BUTTON_PASSTHRU);
joystick.Init();
}