trouble with coding a ESC with a pushbutton

Hello I was hoping one of yall might not be as zombified as me and point out my mistake.

I’m trying to code an ESC to control a brushless motor and have a switch that opens and turn the ESC to full throttle.

I think the ESC needs a potentiometer in order to set itself at startup, so I left that in here.

I can control the esc with the potentiometer with this sketch, but the switch doesn’t do anything, doesn’t turn the esc on or off nor the onboard LED on or off.

Thanks in advance.

/*
        Arduino Brushless Motor Control
     
*/
#include <Servo.h>
Servo ESC;     // create servo object to control the ESC
const int buttonPin = 2;        //number of the pushbutton pin
const int ledPin = 13;          //built in LED
int potValue;  // value from the analog pin
int buttonState = 0;

void setup() {
  // Attach the ESC on pin 9
  ESC.attach(9, 1000, 2000); // (pin, min pulse width, max pulse width in milliseconds)
}
void loop() {
  buttonState = digitalRead(buttonPin);

  // check if pushbutton is pressed. If it is, the button buttonState is LOW:
  if (buttonState == LOW) {
    analogWrite(A0, 0);  //send zero power to ESC
    digitalWrite(ledPin, HIGH);       //LED turn on
  } else {
    //Turn on ESC to full power
    analogWrite(A0, 1023);        //send full power to ESC
    digitalWrite(ledPin, LOW);    //turn off LED
  }
  potValue = analogRead(A0);   // reads the value of the potentiometer (value between 0 and 1023)
  potValue = map(potValue, 0, 1023, 0, 180);   // scale it to use it with the servo library (value between 0 and 180)
  ESC.write(potValue);    // Send the signal to the ESC
}

Three obvious problems.

Whatever you do with the switch is going to be countermanded by the value read from the pot

To control the ESC with the pot you correctly use ESC.write() but with the switch you are trying to control it with analogWrite().

To compound that you attach the ESC to pin 9 then try to set its power by outputting to A0 which is not a PWM capable pin anyway

Thanks but I was able to get it working

/*
        Arduino Brushless Motor Control

*/
#include <Servo.h>
Servo ESC;     // create servo object to control the ESC
const int buttonPin = 2;        //number of the pushbutton pin
const int ledPin = 13;          //built in LED
int potValue;  // value from the analog pin
int buttonState = 0;

void setup() {
  // Attach the ESC on pin 9
  ESC.attach(9, 1000, 2000); // (pin, min pulse width, max pulse width in milliseconds)
}
void loop() {
  buttonState = digitalRead(buttonPin);

  // check if pushbutton is pressed. If it is, the button buttonState is LOW:
  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);       //LED turn on
  } else {
    //Turn on ESC to full power
    potValue = analogRead(A0);   // reads the value of the potentiometer (value between 0 and 1023)
    potValue = map(potValue, 0, 1023, 0, 180);   // scale it to use it with the servo library (value between 0 and 180)
    ESC.write(potValue);    // Send the signal to the ESC
    digitalWrite(ledPin, LOW);    //turn off LED

The code you posted does not even compile.

How is that "working" ?

Well it worked somehow while I had everything laid out with the breadboard, now that I got it together it doesn't. It compiled just fine on my end

It compiled just fine on my end

Then you didn't compile the code that you uploaded. Look at the last line in the code in post #2 Is that really the end of the program ?