diff --git a/examples/type_test/Makefile b/examples/basic/Makefile similarity index 100% rename from examples/type_test/Makefile rename to examples/basic/Makefile diff --git a/examples/type_test/type_test.ino b/examples/basic/basic.ino similarity index 52% rename from examples/type_test/type_test.ino rename to examples/basic/basic.ino index 03f6e35..eacc04e 100644 --- a/examples/type_test/type_test.ino +++ b/examples/basic/basic.ino @@ -2,21 +2,33 @@ // 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 #include 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(); } diff --git a/examples/multiplexer/Makefile b/examples/multiplexer/Makefile new file mode 100644 index 0000000..d1058d4 --- /dev/null +++ b/examples/multiplexer/Makefile @@ -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} diff --git a/examples/multiplexer/multiplexer.ino b/examples/multiplexer/multiplexer.ino new file mode 100644 index 0000000..259e3e2 --- /dev/null +++ b/examples/multiplexer/multiplexer.ino @@ -0,0 +1,49 @@ +// 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 + +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 + uint8_t mux = joystick.AddMux(A1, {A2, A3, A4, A5}, 4); + + // now we can add the rest of the buttons + joystick.AddButton(A1, BUTTON_PASSTHRU, true, true, mux, 1); // the last parameter is which channel/pin the input is attached to on the multiplexer + joystick.AddButton(A1, BUTTON_PASSTHRU, true, true, mux, 2); + joystick.AddButton(A1, BUTTON_PASSTHRU, true, true, mux, 3); + joystick.AddButton(A1, BUTTON_PASSTHRU, true, true, mux, 4); + joystick.AddButton(A1, BUTTON_PASSTHRU, true, true, mux, 5); + joystick.AddButton(A1, BUTTON_PASSTHRU, true, true, mux, 6); + joystick.AddButton(A1, BUTTON_PASSTHRU, true, true, mux, 7); + joystick.AddButton(A1, BUTTON_PASSTHRU, true, true, mux, 8); + + joystick.Init(); +} + +void loop() { + // check all the button states and send any changes + joystick.Update(); +} diff --git a/examples/complex_switch_panel/complex_switch_panel.ino b/examples/obsolete/complex_switch_panel/complex_switch_panel.ino similarity index 100% rename from examples/complex_switch_panel/complex_switch_panel.ino rename to examples/obsolete/complex_switch_panel/complex_switch_panel.ino diff --git a/examples/switch_panel/switch_panel.ino b/examples/obsolete/switch_panel/switch_panel.ino similarity index 100% rename from examples/switch_panel/switch_panel.ino rename to examples/obsolete/switch_panel/switch_panel.ino diff --git a/examples/switch_panel_improved/switch_panel_improved.ino b/examples/obsolete/switch_panel_improved/switch_panel_improved.ino similarity index 100% rename from examples/switch_panel_improved/switch_panel_improved.ino rename to examples/obsolete/switch_panel_improved/switch_panel_improved.ino