analogRead(A2) always at 1019 arduino pro micro

Hi, a month back I tried to make an analog handbrake project for sim racing using an ardiuno pro micro. It didn't work and I had been told that my potentiometer was broken so I bought some new one's which finally arrived.

I plugged just my arduino, without anything connected into my PC via USB. I checked the serial monitor and noticed it's always at 1017-1021, while nothing is connected, if I touch the arduino the values might go lower.

Is this normal or is it the arduino that's broken? I thought it was supposed to be 0 since it shouldn't be reading anything. The only thing physically broken is the A0 connection, it came lose during desoldering my previous connections. So I just use A2 now.

#include <Joystick.h>

void setup()

{pinMode(A2, INPUT_PULLUP); 
   Joystick.begin();}

void loop()
{

  const int pinToButtonMap = A2;
  
  Serial.println(analogRead(pinToButtonMap)); 
  int pot = analogRead(pinToButtonMap);
  int mapped = map(pot,0,1023,0,255);
  {Joystick.setThrottle(mapped);}

}

This line

pinMode(A2, INPUT_PULLUP);

effectively connects the input to 5V and ensures that the analog input will be HIGH if not connected to anything else.

This:

int mapped = map(pot,0,1023,0,255);

can be replaced with the much faster, simpler and smaller operation

int mapped = pot>>2;

jremington:
This line

pinMode(A2, INPUT_PULLUP);

effectively connects the input to 5V and ensures that the analog input will be HIGH if not connected to anything else.

This:

int mapped = map(pot,0,1023,0,255);

can be replaced with the much faster, simpler and smaller operation

int mapped = pot>>2;

Forgot to mention this is not my code, I thought to leave it like it is so I made sure to get the same results.

So it's because of this line that the arduino always reads the max value? Nothing to worry about than right?

pinMode(A2, INPUT_PULLUP);

You should write code that does what you want it to do.

checked the serial monitor and noticed it's always at 1017-1021, while nothing is connected, if I touch the arduino the values might go lower.

Yes when nothing is connected to any input on an Arduino, or any other piece of electronics it can read anything. It is known as a floating input.

That will change when you connect your pot. However make sure you connect it correctly or you might damage it. The wiper on the pot goes to the analogue input and the other two connections go to 5V and ground.