Arduino Leonardo Gamepad Axis problem

Hello there!
I've been practicing and watching tutorials on how to work with the Arduino to make a joystick/gamepad game.

However, I decided to use a potentiometer and control the Y-axis using it.
The problem is that Arduino gets the right inputs, but when I check in the gaming controllers the crosshair is stuck in the upper left corner and won't move. The Y rotation does move.

Here is the code below.

#include "Joystick.h"
Joystick_ Joystick;

int VRy = A0;
int posY = 0;
int mapY = 0;

void setup() {
  Serial.begin(9600);
  Joystick.begin();
  pinMode(VRy, INPUT);
}

void loop(){
  posY = analogRead(VRy);
  mapY = map(posY, 0, 1023, 0, 255);
  Joystick.setRyAxis(posY);
  Serial.println(posY);
  delay(100);
}

What is the purpose of this line and why is mapY never used again?
mapY = map(posY, 0, 1023, 0, 255);

I don't know much about Ardunio. I do know that every tutorial or code I have looked at has the map() line.
It simply gets the input of the potentiometer and set the maximum from 0-1023 and minimum from 0-255 (if I'm correct).

I'm just trying to control the Y axis using the potentiometer, but like I mentioned. In Serial Monitor I can see the values, which works correct, however, in the "Game Controllers" the crosshair is in the corner and won't move except for the bar value shown in the Y rotation.

No, that's not what map does.
Use the Arduino refrence manual.

I think I understand what it does except that most tutorials I watched used it. Then, what can I use to read the inputs and then output them?

The way map is used looks okey, rescaling data from 10 bits (0-1023) to 8 bits (0-255).
Your explanation sounded incorrect.

I tried changing 255 to 180, but that didn't do anything.

As you can see, I made some adjustments and can now move the crosshair. However, the value when I rotate it doesn't change and the crosshair is set in the top middle not in the center.

Place the crosshair in the middle, make a piece of rotate and watch.

Thank you for the help, but that's where I'm stuck. I tried several codes and the crosshair won't center.

Try to learn and understand what the code is doing. Importing new, unknown, code could be a never ending job.
Learn what data the libraries are made to handle, how they work.

What do You mean with "rotating the cross"? How do You it? Like turning a riffle 90 degrees and expect bulls eye?

I meant when I turn the potentiometer (rotate it) the value/bar for the Y axis and the crosshair will move depending which direction I rotate it.

Post a wiring of this setup. I suspect some GND is wrong or missing.


That's what I have, but instead it is connected in A0

That's fine and You read the pot value correctly, I understand. I was waiting for all the wiring, especially from the controller to the other stuff.

Actually, I tested the potentiometer in a game online. It does works. It turns where it is supposed to. I just find it weird that it doesn't show the values in the "Game Controller" properties when I rotate it.

Well, I have no Game controller......
Looks like the problem is solved.

Make the following change and see what happens.

  Joystick.setRyAxis(mapY);