Controlling a brushless motor

Hello, I am building an RC plane, and I am using an Arduino Nano to control a 30A ESC with a 2200kv motor. I have never used a brushless motor before, so I have no experience with this. I tried using several code examples I found on the internet, but none have worked.

This is my current code, which is supposed to receive an integer for the motor power through an NRF24L01 radio transceiver, and set the speed of the motor (pin D3) to this value.

#include <SPI.h> 
#include <nRF24L01.h> 
#include <RF24.h> 
#include <Servo.h>

Servo esc;

int joyArray[1];
int mPower;

RF24 wirelessSPI(7, 8);
const uint64_t Address = 0xB00B1E5000LL;

void setup(){
  esc.attach(3);
  arm(); 
  
  Serial.begin(9600);
  
  wirelessSPI.begin();
  wirelessSPI.setAutoAck(1);        
  wirelessSPI.enableAckPayload();
  wirelessSPI.setRetries(5,15);
  wirelessSPI.openReadingPipe(1,Address);
  wirelessSPI.startListening();
  wirelessSPI.printDetails();
}

void loop(){
  if(wirelessSPI.available()){
    while(wirelessSPI.available()){
      wirelessSPI.read(&joyArray, sizeof(joyArray));
      mPower = joyArray[0];
      setSpeed(mPower);
      delay(15);
    }
  }
}

void arm(){
  setSpeed(100);
  delay(1000);
  setSpeed(0);
  delay(2000);
}

void setSpeed(int speed){
  int angle = map(speed, 0, 100, 0, 180);
  esc.write(angle);    
}

I know the radio transceiver is not the problem, because I can control the servo motors for the elevons with no problem (I deleted the code for the elevons for testing purposes, though). When I plug in the battery, the motor makes beeping sounds, and when I run the code it makes different beeping sounds when I change the throttle to 100 or 0, but it does not turn at all. I think the problem is in the code because based on youtube videos it sounds like the code for arming it and setting the speed should be different for different ESCs, but mine came with no instructions. This is the product I bought from Amazon:

https://www.amazon.com/gp/product/B07D546LXK/ref=oh_aui_detailpage_o08_s00?ie=UTF8&psc=1

Thanks for any help!

Have you verifed the values passed to setSpeed are what you think they are? You probably should be more
defensive in coding things, ie use constrain.

void setSpeed(int speed){
  int angle = constrain (map(speed, 0, 100, 0, 180), 0, 180);
  esc.write(angle);   
}

Yes, I verified that the values are correct. I also added a constrain(), but I do also have a constrain() in the code for the transmitter. Is there any way to determine what values a specific ESC needs to arm? Also, do I need to calibrate the motor/ESC, and if so, how?

Update: It randomly started working and I didn't change anything, but now its sometimes working and sometimes not.

I don’t understand why you are doing this - can’t you just connect the motor controller ( ESC) to the receiver as designed ? This way it’s nice and safe and won’t take your fingers off when you don’t expect it.