ESC rc car not working

Hi, i am making a rc car project and I cant seem to figure out how to use an esc (traxxas XL5hv) with arduino. Basicly what im trying to do is add a ultra sonic sensor to the front of my rc car and everytime it comes close to a wall it should slow down and stop, I just want the motor be controlled through the arduino so I can add the sensor if you have any other Ideas I am ready to hear them. I am using a FLYSKY FS-i6x controller , the code I used as a refrance:

https://dronebotworkshop.com/radio-control-arduino-car/

^to use FlySky fs-i6x with arduino^

https://bluerobotics.com/learn/guide-for-controlling-the-basic-esc-with-a-potentiometer/

^to control the ESC using with an PWM output^

I just cant seem to find how to control my esc with arduino. Ive tryed to use the control an ESC with PWM(and a pot) and change some code to take my controller as an input but the motor spins its just the motor idles at mid point. I can include a video if you dont understand what I mean or even a diragram.

Code:

#include <Servo.h>
// Define Input Connections
#define CH1 8

byte servoPin = 9; // signal pin for the ESC.
Servo servo;
int minLimit;
int maxLimit;
// Integers to represent values from sticks and pots
int ch1Value;

int readChannel(int channelInput, int minLimit, int maxLimit, int defaultValue){
  int ch = pulseIn(channelInput, HIGH, 30000);
  if (ch < 100) return defaultValue;
  return map(ch, 1000, 2000, minLimit, maxLimit);
}

// Read the switch channel and return a boolean value
bool readSwitch(byte channelInput, bool defaultValue){
  int intDefaultValue = (defaultValue)? 100: 0;
  int ch = readChannel(channelInput, 0, 100, intDefaultValue);
  return (ch > 50);
}

void setup(){
  // Set up serial monitor
  Serial.begin(9600);
  
  // Set all pins as inputs
  pinMode(CH1, INPUT);
  
servo.attach(servoPin);
servo.writeMicroseconds(1500); // send "stop" signal to ESC. Also necessary to arm the ESC.

 
}


void loop() {
  
  // Get values for each channel
  ch1Value = readChannel(CH1, -100, 100, 0);

  
  // Print to Serial Monitor
  Serial.println(ch1Value);

int pwmVal = map(ch1Value,0, 1023, 1100, 1900); // maps potentiometer values to PWM value.


  servo.writeMicroseconds(pwmVal); // Send signal to ESC.

  delay(500);
}

Note: The motor should go forward and Reverse (50/50).

Thanks alot for reading Ive been stuck here for the past week!

If you have a diagram, post it.