I don't see how could I draw something that would make it clearer, but let me try to rephrase my question, as I think it wasn't very clear in my first message.
I want to build a button box, recognizable by the computer as a gaming controller, using the joystick library. Ideally and if possible, I would like to only have one cable going to the computer, so it's detected as only one device.
It needs 74 buttons, and the most efficient way to do that is with a matrix (it should be a 9x9 matrix). But I need the 4 analog inputs (unless I used a multiplexer, but even then, I wouldn't have enough digital inputs).
If it can't be done, I know how to do it with 2 boards, two cables and two devices being detected by the computer, I've done multiple button boxes of over 40 inputs.
So my question is, can it be done only with one cable going out? And if so, in a very general way, how would you suggest to do it?
I was expecting replies in the lines of:
- No, you can't do that. Windows won't recognize any gaming device with more than 64 inputs.
Or
- Yes, you just need to add x number of I/O expanders in parallel
So at this point I'm not looking for a specific solution, just want to know if it's even possible.
Full code below for reference:
#include <PCF8575.h>
#include <Keypad.h>
#include <Joystick.h>
PCF8575 pcf8575(0x20);
#define NUMROWS 9
#define NUMCOLS 9
#define joyX A3
#define joyY A2
#define joyRX A1
#define joyRY A0
#define gain A10
#define lev A9
byte buttons[NUMROWS][NUMCOLS] = {
{0,1,2,3,4,5,6,7,8},
{9,10,11,12,13,14,15,16,17},
{18,19,20,21,22,23,24,25,26},
{27,28,29,30,31,32,33,34,35},
{36,37,38,39,40,41,42,43,44},
{45,46,47,48,49,50,51,52,53},
{54,55,56,57,58,59,60,61,62},
{63,64,65,66,67,68,69,70,71},
{72,73,74,75,76,77,78,79,80},
};
byte rowPins[NUMROWS] = {P0,P1,P2,P3,P4,P5,P6,P7,5};
byte colPins[NUMCOLS] = {P8,P9,P10,P11,P12,P13,P14,P15,7};
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
//Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 81, 0, true, true, false, true, true, false, true, true, false, false, false);
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK, 81, 0, true, true, false, true, true, false, false, false, false, false, false);
const bool initAutoSendState = true;
int xAxis_ = 0;
int yAxis_ = 0;
int rxAxis_ = 0;
int ryAxis_ = 0;
int rudder_ = 0;
int throttle_ = 0;
void setup() {
Joystick.begin();
pcf8575.begin();
}
void loop() {
CheckAllAxis();
CheckAllButtons();
}
void CheckAllAxis(void) {
xAxis_ = analogRead(joyX);
xAxis_ = map(xAxis_, 0, 1023, 255, 0);
Joystick.setXAxis(xAxis_);
yAxis_ = analogRead(joyY);
yAxis_ = map(yAxis_, 0, 1023, 0, 255);
Joystick.setYAxis(yAxis_);
rxAxis_ = analogRead(joyRX);
rxAxis_ = map(rxAxis_, 0, 1023, 0, 255);
Joystick.setRxAxis(rxAxis_);
ryAxis_ = analogRead(joyRY);
ryAxis_ = map(ryAxis_, 0, 1023, 0, 255);
Joystick.setRyAxis(ryAxis_);
rudder_ = analogRead(gain);
rudder_ = map(rudder_, 0, 1023, 0, 255);
Joystick.setRudder(rudder_);
throttle_ = analogRead(lev);
throttle_ = map(throttle_, 0, 1023, 0, 255);
Joystick.setThrottle(throttle_);
}
void CheckAllButtons(void) {
if (buttbx.getKeys())
{
for (int i=0; i<LIST_MAX; i++)
{
if ( buttbx.key[i].stateChanged )
{
switch (buttbx.key[i].kstate) {
case PRESSED:
case HOLD:
Joystick.setButton(buttbx.key[i].kchar, 1);
break;
case RELEASED:
case IDLE:
Joystick.setButton(buttbx.key[i].kchar, 0);
break;
}
}
}
}
}
Thanks