Rework example code, fix bugs and get to compiling state. Also introduce missing logic for the Matrix code to keep track of what column is active.

This commit is contained in:
2021-11-22 20:10:08 +00:00
parent 8ebc1a5523
commit 690afdbce5
18 changed files with 194 additions and 26 deletions

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}

View File

@ -0,0 +1,40 @@
// 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 namespace admux;
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);
Mux* mux = new Mux(Pin(9, INPUT_PULLUP, PinType::Digital), Pinset(10, 11, 12, 13));
joystick.AddButton(0, BUTTON_PASSTHRU, true, mux);
// start up serial communication
joystick.Init();
}
void loop() {
// check all the button states and send any changes
joystick.Update();
}