Hello again! Thank you everyone for the help. I apologize for the late reply. I took a break from this project for a few days. I have some more information that I hope will help. I drew a very crude schematic of my setup using Kicad. It's not pretty, but I hope it's enough for you to see what I've done. The "Arduino_Leonardo_Shield" symbol depicted in the schematic has a different pin layout than the actual board, but the pin labels are the same. I could not find a symbol for an analog stick with center click on Kicad, so I added 2 dual potentiometers with 2 push buttons to the left of the symbols labeled "Joystick". I also had to edit the rotary encoder symbol to better reflect the rotary encoder that I have purchased for this setup. The reason I connected the rotary encoder's CLK and DT to pin 2 and 3, is because they support interrupts. I read somewhere that this is important, but I can't remember why. I also had to update the code because I have changed a few pin connections since my first post.
As @robby77 mentioned, I don't think that XInput supports the use of rotary encoders. This is probably due to XInput only having a set amount of controls (buttons, Potentiometers, etc.). It's only emulating the controls that an Xbox controller has. I may have to look into using DirectInput instead. That would allow me to use more controls for my games, including a rotary encoder for the steering wheel.
My goal is to play driving simulator games using this DIY controller. I will do some more research on implementing DirectInput. Let me know if there is any other information that could help.
Here is the updated code:
#include <XInput.h>
#include <Rotary.h>
Rotary rotary = Rotary(2, 3);
int counter = 0;
void setup() {
{
Serial.begin(57600);
attachInterrupt(0, rotate, CHANGE);
attachInterrupt(1, rotate, CHANGE);
}
XInput.setAutoSend(false);
XInput.setJoystickRange(0, 1023);
XInput.begin();
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
}
void loop() {
XInput.setTrigger(TRIGGER_LEFT, analogRead(A0));
XInput.setTrigger(TRIGGER_RIGHT, analogRead(A1));
XInput.setJoystick(JOY_LEFT, analogRead(A2), analogRead(A3));
XInput.setJoystick(JOY_RIGHT, analogRead(A4), analogRead(A5));
XInput.setButton(BUTTON_A, !digitalRead(4));
XInput.setButton(BUTTON_B, !digitalRead(5));
XInput.setButton(BUTTON_X, !digitalRead(6));
XInput.setButton(BUTTON_Y, !digitalRead(7));
XInput.setButton(BUTTON_LB, !digitalRead(8));
XInput.setButton(BUTTON_RB, !digitalRead(9));
XInput.setButton(BUTTON_L3, !digitalRead(10));
XInput.setButton(BUTTON_R3, !digitalRead(11));
XInput.send();
}
void rotate() {
unsigned char result = rotary.process();
if (result == DIR_CW) {
counter++;
Serial.println(counter);
} else if (result == DIR_CCW) {
counter--;
Serial.println(counter);
}
}
The schematic:
A picture of my terrible wire management:

