I'm stuck, I figured I'd ask here for some help... Note I'm a newb and this is essentially my first Arduino project beyond blink...
I'm creating Virtual cockpit panels for DCS World, using an Arduino Leonardo as an HID device. I'm using three SN74HC165 Shift-In registers for multi-buttons (24) - as it seemed the easiest - and all in all it does work...
So I figured that I'm using only 4 pins on the Leonardo, so why not try to setup 3 of these "shift-in clusters" (12 pins) to appear as 3 separate joysticks?
I got the one working and I got 2 more joysticks showing up in Windows10... now my problem is: how would I setup 2 more "shiftIn Clusters", I've tried many things but I must defer to outside help (cause I really don't know what I'm doing)
Edit to clarify: So each joystick need 3 or 4 shift registers making 24-32 buttons on each joystick
Shift In Lib: https://github.com/…/Ardu…/blob/master/ShiftIn/src/ShiftIn.h
Joy2 Lib: https://github.com/MHeironimus/ArduinoJoystickLibrary
Here's an image of the Layout I want: https://i.imgur.com/eZfMMzI.png
... any help would relieve a great headache, Thank for your time
#include <ShiftIn.h>
#include <Joystick.h>
// use <n> shift registers
ShiftIn<3> shift; // use three shift register
// Create joystick
// TESTING MULTI JOYSTICKS
// 1/3 Works!!!
// 3/3 Appear in Windows
// ????? must add shiftIn sections for 2nd and 3rd joysticks????
// (add pin usage + modify line 77-79 stuff)
#define JOYSTICK_COUNT 3
Joystick_ Joystick[JOYSTICK_COUNT] = {
Joystick_(0x03, JOYSTICK_TYPE_GAMEPAD, 32, 0, false, false, false, false, false, false, false, false, false, false, false),
Joystick_(0x04, JOYSTICK_TYPE_GAMEPAD, 32, 0, false, false, false, false, false, false, false, false, false, false, false),
Joystick_(0x05, JOYSTICK_TYPE_GAMEPAD, 32, 0, false, false, false, false, false, false, false, false, false, false, false),
};
// Set to true to test "Auto Send" mode or false to test "Manual Send" mode.
//const bool testAutoSendMode = true;
const bool testAutoSendMode = false;
const unsigned long gcCycleDelta = 1000;
const unsigned long gcAnalogDelta = 25;
const unsigned long gcButtonDelta = 500;
unsigned long gNextTime = 0;
unsigned int gCurrentStep = 0;
int gJoystickId = 0;
/*
// WORKING SECTION Single Joystick with Shift Reg
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD,
32, 0, // Button Count, Hat Switch Count
false, false, false, // X and Y, but no Z Axis
false, false, false, // No Rx, Ry, or Rz
false, false, // No rudder or throttle
false, false, false); // No accelerator, brake, or steering
*/
void setup() {
shift.begin(8, 9, 11, 12); // set pins of the shift register
// shift[1].begin(7, 6, 5, 4); // set pins of the shift register
// shift[2].begin(3, 2, 1, 0); // set pins of the shift register
Joystick[0].begin();
Joystick[1].begin();
Joystick[2].begin();
}
void loop() {
if (shift.update()) {
for (int i = 0; i < shift.getDataWidth(); i++)
Joystick[0].setButton(i, shift.state(i)); // just press or release the button
}
/*if (shift[1].update()) {
for (int i = 0; i < shift[1].getDataWidth(); i++)
Joystick[0].setButton(i, shift[1].state(i)); // just press or release the button
}
if (shift[2].update()) {
for (int i = 0; i < shift[2].getDataWidth(); i++)
Joystick[0].setButton(i, shift[2].state(i)); // just press or release the button
}
delay(10);
*/
}