Can a Linear slide pot be used to emulate the X or Y axis of a Joystick?

I have a project that i started working on that requires a slide pot to mirror a single axis of a joystick. I’m using a Arduino Leonardo board and the joystick library. I can see the pot working correctly on the serial plotter and windows recognizes the board as a Controller.

I am having trouble assigning the analog output to either the X or Y axis on the controller in windows.

Is this even possible??

Sample code i used to verify the board is reading the analog input.

#include <Joystick.h>

  Reads an analog input on pin 0, prints the result to the serial monitor.
  Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.

  false, false, false, false, false, false,
  false, false, false, false, true);

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
 while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB

  Joystick.setXAxisRange(0, 1023);

  // Init Pins
  pinMode(A0, INPUT);

// the loop routine runs over and over again forever:
void loop() {
  //tweak the joystick state (see joystick.h for all possible fields)
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);

  // print out the value you read:
  delay(20);        // delay in between reads for stability

I think the pot is wired correctly as the plot verifies output changes while sliding the arm.

Any help would be greatly appreciated.


Do not cross-post. Other thread removed.

Noted, I apologize for that. I noticed i posted the original thread in the wrong fourm.


It doesn't run on an Arduino, but for this sort of thing I've found FreeJoy works really well. The hardware to run it is still very cheap too.

Thanks for the info. I have a board on the way to test.