53 lines
1.9 KiB
C++
53 lines
1.9 KiB
C++
// 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();
|
|
}
|