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:
8
example/obsolete/basic/Makefile
Normal file
8
example/obsolete/basic/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}
|
34
example/obsolete/basic/basic.ino
Normal file
34
example/obsolete/basic/basic.ino
Normal file
@ -0,0 +1,34 @@
|
||||
// An example sketch using the joystick library.
|
||||
// In this example, we have 3 toggle switches and 2 momentary pushbuttons.
|
||||
// Each button is configured in a different one of the available behaviors.
|
||||
|
||||
#include <Joystick.h>
|
||||
|
||||
bool debug = false;
|
||||
Joystick joystick(debug);
|
||||
|
||||
void setup() {
|
||||
// momentary pushbutton #1
|
||||
joystick.AddButton(9, BUTTON_PASSTHRU);
|
||||
|
||||
// momentary pushbutton #2 - this one will toggle on or off each time it is pushed
|
||||
joystick.AddButton(10, BUTTON_LATCHED_MOMENTARY);
|
||||
|
||||
// a toggle switch that acts like a momentary button - every time it's toggled 'on' it briefly sends
|
||||
// a keypresss
|
||||
joystick.AddButton(11, BUTTON_PULSED);
|
||||
|
||||
// like the above, but it sends its button press when toggled on *and* when toggled off
|
||||
joystick.AddButton(12, BUTTON_PULSED_DOUBLE_ACTION);
|
||||
|
||||
// again, similar to the above, but it sends two *different* button presses - 'on' will be one button, 'off' another.
|
||||
joystick.AddButton(13, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
|
||||
// start up serial communication
|
||||
joystick.Init();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check all the button states and send any changes
|
||||
joystick.Update();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
// A button box example using all of the button types.
|
||||
// This is the code used in the Black Box project.
|
||||
// TODO: add link to blog post, once it exists.
|
||||
|
||||
#include <Bounce2.h>
|
||||
#include <Joystick.h>
|
||||
|
||||
Joystick joystick;
|
||||
|
||||
void setup() {
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
joystick.Init();
|
||||
// 3 toggle switches that emit a press every time they are toggled.
|
||||
// (in either direction)
|
||||
joystick.AddButton(2, BUTTON_PULSED_DOUBLE_ACTION);
|
||||
joystick.AddButton(3, BUTTON_PULSED_DOUBLE_ACTION);
|
||||
joystick.AddButton(4, BUTTON_PULSED_DOUBLE_ACTION);
|
||||
|
||||
// This button will stay 'held down' as long as the switch is on.
|
||||
joystick.AddButton(6, BUTTON_LATCHED);
|
||||
|
||||
// This button will emit a short press every time it is pushed, but
|
||||
// only one per push.
|
||||
joystick.AddButton(8, BUTTON_PULSED);
|
||||
}
|
||||
|
||||
void loop () {
|
||||
joystick.Update();
|
||||
}
|
8
example/obsolete/full/Makefile
Normal file
8
example/obsolete/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}
|
40
example/obsolete/full/full.ino
Normal file
40
example/obsolete/full/full.ino
Normal 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();
|
||||
}
|
8
example/obsolete/multiplexer/Makefile
Normal file
8
example/obsolete/multiplexer/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}
|
52
example/obsolete/multiplexer/multiplexer.ino
Normal file
52
example/obsolete/multiplexer/multiplexer.ino
Normal file
@ -0,0 +1,52 @@
|
||||
// An example sketch using the joystick library, demonstrating multiplexer support
|
||||
// In this example, we have 21 buttons we want to attach.
|
||||
// Unfortunately, the Arduino Uno only has 17 pins we can use!
|
||||
// So we've added an 8-channel multiplexer, connected to pins A1-A5.
|
||||
//
|
||||
// Note: this may not be the best approach for this many simple buttons. Using an input matrix
|
||||
// would require as few as 10 inputs in this scenario, for example. This is just a demo :)
|
||||
|
||||
#include <Joystick.h>
|
||||
#include <Mux.h>
|
||||
|
||||
using namespace admux;
|
||||
|
||||
bool debug = false;
|
||||
Joystick joystick(debug);
|
||||
|
||||
void setup() {
|
||||
// All of our digital pins and A0 are taken up with pushbuttons
|
||||
joystick.AddButton(2, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(3, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(4, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(5, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(6, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(7, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(8, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(9, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(10, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(11, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(12, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(13, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(A0, BUTTON_PASSTHRU);
|
||||
|
||||
// to get more room for our inputs, we add an 8-bit multiplexer
|
||||
Mux* mux = new Mux(Pin(A1, INPUT_PULLUP, PinType::Digital), Pinset(A2, A3, A4, A5));
|
||||
|
||||
// now we can add the rest of the buttons
|
||||
joystick.AddButton(0, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(1, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(2, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(3, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(4, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(5, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(6, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(7, BUTTON_PASSTHRU, true, mux);
|
||||
|
||||
joystick.Init();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check all the button states and send any changes
|
||||
joystick.Update();
|
||||
}
|
59
example/obsolete/switch_panel/switch_panel.ino
Normal file
59
example/obsolete/switch_panel/switch_panel.ino
Normal file
@ -0,0 +1,59 @@
|
||||
// An example sketch using the joystick library.
|
||||
// In this example, we have 5 toggle switches that are configured
|
||||
// as double-action pulsed buttons - that is, whenever they are toggled, they
|
||||
// emit a short button press.
|
||||
//
|
||||
// This example uses the *old* Joystick API. You should strongly prefer the
|
||||
// other, better examples in this directory!
|
||||
|
||||
#include <Bounce2.h>
|
||||
#include <Joystick.h>
|
||||
|
||||
bool debug = false;
|
||||
Joystick joystick(debug);
|
||||
|
||||
// Number of connected buttons.
|
||||
int num_buttons = 5;
|
||||
// Last known state of each pin.
|
||||
int states[10] = {-1, -1, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
|
||||
|
||||
void parsePins(bool init=false) {
|
||||
// Input: figure out which pins have changed.
|
||||
bool something_pressed = false;
|
||||
for (int i = 2; i < 2 + num_buttons; i++) {
|
||||
int newstate = digitalRead(i);
|
||||
if (newstate != states[i]) {
|
||||
states[i] = newstate;
|
||||
if (!init) {
|
||||
joystick.PressButton(i-2);
|
||||
something_pressed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output: Actually press the appropriate buttons, wait, then clear them all.
|
||||
if (something_pressed) {
|
||||
joystick.Write();
|
||||
joystick.ReleaseAllButtons();
|
||||
joystick.Write();
|
||||
}
|
||||
}
|
||||
|
||||
void InitInputs() {
|
||||
for (int i = 2; i < 2 + num_buttons; i++) {
|
||||
pinMode(i, INPUT_PULLUP);
|
||||
}
|
||||
parsePins(true);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, LOW);
|
||||
joystick.Init();
|
||||
InitInputs();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
parsePins();
|
||||
if (debug) delay(900);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
// This is the same 5-toggle-switch example from switch_panel.ino, using the
|
||||
// new API. So much easier!
|
||||
|
||||
#include <Bounce2.h>
|
||||
#include <Joystick.h>
|
||||
|
||||
Joystick joystick;
|
||||
|
||||
void setup() {
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, LOW);
|
||||
|
||||
joystick.Init();
|
||||
joystick.AddButton(2, BUTTON_PULSED_DOUBLE_ACTION, true);
|
||||
joystick.AddButton(3, BUTTON_PULSED_DOUBLE_ACTION, true);
|
||||
joystick.AddButton(4, BUTTON_PULSED_DOUBLE_ACTION, true);
|
||||
joystick.AddButton(5, BUTTON_PULSED_DOUBLE_ACTION, true);
|
||||
joystick.AddButton(6, BUTTON_PULSED_DOUBLE_ACTION, true);
|
||||
}
|
||||
|
||||
void loop () {
|
||||
joystick.Update();
|
||||
}
|
Reference in New Issue
Block a user