I've been working on a project to make a video game steering wheel for PC, using a rotary encoder. I know very little about programming, in general. I have all of the hardware wired up correctly, and the code is mostly complete. I'm using an XInput library to control the six buttons, two joysticks with push switch, two potentiometers and the rotary encoder. Everything works as intended, except for the rotary encoder. The serial monitor displays very accurate values, so I know that it's reading correctly. I just can't figure out, after a whole week of tinkering and problem-solving, how to get it to interface with any game or mapping software that I've tried to use. I just want to control my games with this DIY controller. The microcontroller that I am using is the Arduino Leonardo. Can anyone help me figure this out? Any help is appreciated.
Here is my current 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(12, INPUT_PULLUP);
pinMode(13, 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(10));
XInput.setButton(BUTTON_B, !digitalRead(11));
XInput.setButton(BUTTON_X, !digitalRead(4));
XInput.setButton(BUTTON_Y, !digitalRead(5));
XInput.setButton(BUTTON_LB, !digitalRead(6));
XInput.setButton(BUTTON_RB, !digitalRead(7));
XInput.setButton(BUTTON_L3, !digitalRead(12));
XInput.setButton(BUTTON_R3, !digitalRead(13));
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);
}
}