Beginner question with the HC-SR04 sensor

So I’ve recently starting coding on the arduino in the past few weeks and I’ve run into a problem with one of my codes. I want to continuously vary the max distance of the sensor using a potentiometer and every seems to be right in my code but it doesn’t seem to transfer to my sensor. Is it because the max distance must be a constant integer or is my coding just off? Any help would be appreciated. I have attached my code so far below (ignore the side notes i made to myself).

#include <NewPing.h>

unsigned int time;
int distance;
int potMeter = A5;
int val = 0;
#define val analogRead (potMeter)
//val = constrain (val, 200, 823); // Constrain slightly so one doesnt have to turn knob all the way
#define MAX_DISTANCE map (val, 0, 1023, 30, 366) // Taking the values from the potentionmeter and converting it to a distance
NewPing sonar(11,12,MAX_DISTANCE);
//POSSIBLY PUT ON PWM PINS

void setup() {
Serial.begin (9600);
}

void loop() {
time = sonar.ping();
distance = time / US_ROUNDTRIP_IN; //returns distance in inches
if (distance == 0) distance = MAX_DISTANCE;
Serial.println(distance);
delay (100);
// if distance <= MAX_DISTANCE digitalWrite whatever high think about inches and cm. may have to make distance cm or multiply it by 2.54
// At the very end a small delay should be added like 10 miliseconds
}

I’m using an arduino micro if that counts for anything.