Add rotary encoder support, simplify AddMuxButton interface.
This commit is contained in:
8
examples/full/Makefile
Normal file
8
examples/full/Makefile
Normal 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
38
examples/full/full.ino
Normal 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();
|
||||
}
|
Reference in New Issue
Block a user