arduino-joystick/example/obsolete/full/full.ino

41 lines
1.6 KiB
Arduino
Raw Permalink Normal View History

// 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();
}