My game will not recognize my potentiometer

I have code working for my custom game controller, but I want to modify the controller which means adding 2 potentiometers. The code is made for a button matrix and an arduino joystick module. (picture below). The module consists of a potentiometer for each axis so in theory I should be able to remove the current arduino joystick and plug in a potentiometer (linked below) and it should work... Good news is the PC recognizes it without a problem, but the game does not. Does anyone have an idea why this is happening? Both are 10K pots and I know everything is wired correctly because the pot works on the PC, just not in the game.

I have my code posted in case there might be an issue with that, but I don't think that is the culprit. Any guidance would be appreciated. Thanks

#include <Joystick.h>

#define joyButton1 14
#define NUMROWS 3
#define NUMCOLS 2

char buttons[NUMROWS][NUMCOLS] = {
  {1,2},
  {3,4},
  {5,6}
};

byte rowPins[NUMROWS] = {A0,A1,A2};
byte colPins[NUMCOLS] = {2,3};

Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Joystick_ Joystick(0x03, JOYSTICK_TYPE_JOYSTICK, 7, 0, true, true, false, false, false, false, false, false, false, false, false);


void joylights(int x){
 
    for (int c=0;c<x+1;c++)
    {
    Joystick.setButton(1, true);
    Joystick.sendState();
    delay(1000);
    Joystick.setButton(1, false);
    Joystick.sendState();
    }

}

void setup() {
  pinMode(joyButton1, INPUT_PULLUP);
  Joystick.begin(false);
  delay(5000);
  joylights(4);
  }
 
void loop() {
  int thebuttonnumber=0;
  Joystick.setXAxis(analogRead(A9));
  Joystick.setYAxis(1024 - analogRead(A10));
  Joystick.setButton(0, !digitalRead(joyButton1));

  if (buttbx.getKeys())
  {
    for (int i = 0; i < LIST_MAX; i++) // Scan the whole key list.
    {
      if ( buttbx.key[i].stateChanged )   // Only find keys that have changed state.
      {
       switch (buttbx.key[i].kstate) {  
          case PRESSED:
            Joystick.setButton(buttbx.key[i].kcode+1, true);
            break;
          case RELEASED:
            Joystick.setButton(buttbx.key[i].kcode+1, false);
            break;
        }
      }
    }
  }
  Joystick.sendState();
  }

Complete schematic please...no fritzing.

Not pictures either. They are not schematics.

What is the code exercising this setup?

How do you know that it works on the PC but not your game? Does it always work when you use the joystick? Maybe you can try to set includeYAxis to false in Joystick(). It might also be an error in the game code when Yax == 1024 (always held up) or something similar since you say it works on the PC.

The code is above...

I know the code works on the PC because of joy.cpl, the game controller panel

I would assume it works then.
You said: "I know everything is wired correctly because the pot works on the PC, just not in the game."
What game?
If it works in the game controller panel, then "the game" is at fault.

Farm Sim 22, it is a "full controller support" game. I know the arduino joystick works in the game, so I know it recognizes the input of a pot

If you can see the joystick move left and right in the game controller panel when you turn the pot, then the problem is not in the wiring or the Arduino code.

I don't know how we could help you at this point :confused:
Maybe try restarting the game?

I was not sure that this would be the right place to ask for help, but it was worth a shot.

I have uninstalled the game, no dice. Thanks anyway!

Apparently the Op cannot understand plain English (point 1) ......or the difference (point 2)

Another thing...which Arduino are you using to allow analog input on pin 9..??

what I have in my schematic :slight_smile:

Nope...sorry to disappoint but what you have is neither a schematic nor complete.
Good luck with whatever it is.

Are you sure? Again…. It works with the arduino joystick module

I don't see anything wrong with the hardware connections

You would need TWO potentiometers (X/HORZ and Y/VERT) and a pushbutton (SEL)
X range is 0 to 1023
Y range is 0 to 1023
SEL range is 0 and 1

Try this simulation:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.