using pullstime

the m1.writeMicroseconds(1000); is for when nothing is pressed, so the motor speed would go to zero (1000), and the myPulsetime = (mypulseTime + pulseIncrement); is for the variation of speed

I get that, but you are not writing myPulsetime to m1

You seem to know how to write 1000 to m1 so have a wild guess as to how you would write myPulsetime to it.

I appreciate your faith in me man, but I am quite sceptical I know what I am doing, would it be

m1.writemyPulsetime = (mypulseTime + pulseIncrement); ?

also, do you know what Johnwasser meant in the first comment of this page? the if you add the missing code to increment 'buttonPushCounter' when the button is pushed.

would it be

No

Take a deep breath and get your brain in gear.

If you want to write 1000 to m1 you use

m1.writeMicroseconds(1000);

This uses the Servo library function to write a value to the ESC. The value in this case is 1000.

You perform a calculation like this

myPulsetime = (mypulseTime +  pulseIncrement);

after which myPulsetime has a value.

As an aside, how would you print that value ?

Rather than printing it you want to write the value of myPulsetime to m1. You know how to write 1000, so substitute myPulsetime for 1000 in the command and you will have written the value of myPulsetime to m1.

I do not want to simply give you the answer because it is important to think for yourself

I'd probably use the serial print, or is it a hit and miss?

Right, so I took my code which was edited by Johnwasser, which compiles however I can't figure out if I should connect the button pin A2 to ground or to 5 volts

#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;

const int PulseTimeBase = 1000;
const int PulseTimeIncrement = 250;
int myPulseTime = PulseTimeBase;


int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;  
int LastbuttonSate = 0;// current state of the button

void setup()
{
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

  m1.attach(9);
}

void loop()
{
  buttonState = digitalRead(buttonPin);

  switch (buttonPushCounter)
  {
    case 1:  // 1/4 speed and reset the push counter
      buttonPushCounter = 0;
      myPulseTime = PulseTimeBase + PulseTimeIncrement;
      break;
    
     case 2:  // First push: 1/2 speed
      myPulseTime = PulseTimeBase + PulseTimeIncrement + PulseTimeIncrement;
      break;

    case 3: // Second push: 3/4 speed
      myPulseTime = PulseTimeBase + PulseTimeIncrement + PulseTimeIncrement + PulseTimeIncrement;
      break;

    case 4: // Third push: Full speed
      myPulseTime = PulseTimeBase + PulseTimeIncrement + PulseTimeIncrement + PulseTimeIncrement + PulseTimeIncrement;
      break;


    default:  // reset  and reset the push counter
      buttonPushCounter = 0;
      myPulseTime = PulseTimeBase;
      break;




  }
  m1.writeMicroseconds(myPulseTime );
}

Matyk:
I'd probably use the serial print, or is it a hit and miss?

Yes, you would use Serial.print(). What would the command look like ?

I would either do

Serial.print(myPulsetime = (mypulseTime + pulseIncrement));

or Serial.print(1000)

However, I kind of got over that version so what do you think about this code? what should I connect the A2 to ground/ 5 volts? It wasn't written by me I just edited it a bit.thanks for the help, man I really appreciate it

#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;

const int PulseTimeBase = 1000;
const int PulseTimeIncrement = 250;
int myPulseTime = PulseTimeBase;


int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;  
int LastbuttonSate = 0;// current state of the button

void setup()
{
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

  m1.attach(9);
}

void loop()
{
  buttonState = digitalRead(buttonPin);

  switch (buttonPushCounter)
  {
    case 1:  // 1/4 speed and reset the push counter
      buttonPushCounter = 0;
      myPulseTime = PulseTimeBase + PulseTimeIncrement;
      break;
    
     case 2:  // First push: 1/2 speed
      myPulseTime = PulseTimeBase + PulseTimeIncrement + PulseTimeIncrement;
      break;

    case 3: // Second push: 3/4 speed
      myPulseTime = PulseTimeBase + PulseTimeIncrement + PulseTimeIncrement + PulseTimeIncrement;
      break;

    case 4: // Third push: Full speed
      myPulseTime = PulseTimeBase + PulseTimeIncrement + PulseTimeIncrement + PulseTimeIncrement + PulseTimeIncrement;
      break;


    default:  // reset  and reset the push counter
      buttonPushCounter = 0;
      myPulseTime = PulseTimeBase;
      break;




  }
  m1.writeMicroseconds(myPulseTime );
}
Serial.print(myPulsetime = (mypulseTime +  pulseIncrement));

Why make the code more obscure than it needs to be ?

Why not more obviously

myPulsetime = myPulsetime +  pulseIncrement;
Serial.print(myPulsetime);

Similarly

myPulsetime = myPulsetime +  pulseIncrement;
m1.writeMicroseconds(myPulsetime);

And how about this?

#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
const int mypulsebase =  (1000);
const int pulseIncrement = (250);
const int myPulsetime =  mypulsebase;


int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonPushCounter % 1 == 0) {
    m1.attach(9);
    m1.writeMicroseconds(myPulsetime + pulseIncrement);
    delay(1);
  } else {
    m1.writeMicroseconds(1000);
    delay(1);



    if (buttonPushCounter % 3 == 0) {
      m1.attach(9);
      m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement);
      delay(1);
    } else {
      m1.writeMicroseconds(1000);
      delay(1);



      if (buttonPushCounter % 4 == 0) {
        m1.attach(9);
        m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement);
        delay(1);
      } else {
        m1.writeMicroseconds(1000);
        delay(1);


        if (buttonPushCounter % 5 == 0) {
          m1.attach(9);
          m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement + pulseIncrement);
          delay(1);
        } else {
          m1.writeMicroseconds(1000);
          delay(1);





        }
      }
    }
  }
}

Do you think that it would be a good idea to change the value of buttonPushCounter somewhere in the program ?

maybe like this?

if (buttonPushCounter % 1 == 1) {
m1.attach(9);
m1.writeMicroseconds(myPulsetime + pulseIncrement);
delay(1);
} else {
m1.writeMicroseconds(1000);
delay(1);

if (buttonPushCounter % 2 == 2) {
m1.attach(9);
m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement);
delay(1);
} else {
m1.writeMicroseconds(1000);
delay(1);

if (buttonPushCounter % 3 == 3) {
m1.attach(9);
m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement);
delay(1);
} else {
m1.writeMicroseconds(1000);
delay(1);

if (buttonPushCounter % 4 == 4) {
m1.attach(9);
m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement + pulseIncrement);
delay(1);
} else {
m1.writeMicroseconds(1000);
delay(1);

}
}
}
}
}

or maybe this

int buttonPushCounter = buttonstate; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0;

I am beginning to think that you are pretending not to understand on purpose.

In order for the value written to m1 to vary depending on how many times the button has been pushed you must count the button pushes, perhaps by adding one to it every time the button becomes pressed. That is presumably what the buttonPushCounter variable is for judging by its name.

Where in you latest code suggestions do you add one to buttonPushCounter when the button becomes pressed ?

Once that has been sorted out we can tackle the rest of your code which is at best clumsy and repetitive at at its worse just plain wrong.

Look I know that I am bad, so this going to take a long time because sometimes the language you use is proper expert even if simplified, for me it is still complicated, sorry
would this do it?

#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
const int mypulsebase =  (1000);
const int pulseIncrement = (250);
const int myPulsetime =  mypulsebase;


int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonPushCounter+1) {
    m1.attach(9);
    m1.writeMicroseconds(myPulsetime + pulseIncrement);
    delay(1);
  } else {
    m1.writeMicroseconds(1000);
    delay(1);



    if (buttonPushCounter+2) {
      m1.attach(9);
      m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement);
      delay(1);
    } else {
      m1.writeMicroseconds(1000);
      delay(1);



      if (buttonPushCounter+3) {
        m1.attach(9);
        m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement);
        delay(1);
      } else {
        m1.writeMicroseconds(1000);
        delay(1);


        if (buttonPushCounter+4) {
          m1.attach(9);
          m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement + pulseIncrement);
          delay(1);
        } else {
          m1.writeMicroseconds(1000);
          delay(1);





        }
      }
    }
  }
}

Matyk:
would this do it?

It compiles without error or warning. Does it do what you want it to do?
I don't see any place where 'buttonPushCounter' is set to anything other than 0.

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonPushCounter+1) {
    m1.attach(9);
    m1.writeMicroseconds(myPulsetime + pulseIncrement);
    delay(1);
  } else {
...
  }
}

Since buttonState is set but not used and buttonPushCounter is always 0 this is equivalent to:

void loop() {
    m1.attach(9);
    m1.writeMicroseconds(1250);
    delay(1);
}

I don't think that will do what you wanted.

it compiles without an error, but I dont know how I would make it add the button push counter, would this do it?

int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0;

void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);

}

void loop() {
buttonState = digitalRead(buttonPin);

if (buttonPushCounter == 1) {
m1.attach(9);
m1.writeMicroseconds(myPulsetime + pulseIncrement);
delay(1);
} else {
m1.writeMicroseconds(1000);
delay(1);

if (buttonPushCounter == 2) {
m1.attach(9);
m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement);
delay(1);
} else {
m1.writeMicroseconds(1000);
delay(1);

if (buttonPushCounter == 3) {
m1.attach(9);
m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement);
delay(1);
} else {
m1.writeMicroseconds(1000);
delay(1);

if (buttonPushCounter == 4) {
m1.attach(9);
m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement + pulseIncrement);
delay(1);
} else {
m1.writeMicroseconds(1000);
delay(1);

}
}
}
}
}

Please can you learn to do one simple thing to make life easier for those of us who are trying to help you. It has nothing to do with coding so don't panic

Next time you post any code, Auto Format it in the IDE first then copy it and paste it to your post, select it and click on the </> icon above the editor window to add code tags.

Doing that makes the code easier to read and copy to an editor. Look at the difference between John/my posts that contain code and yours

Matyk:
it compiles without an error, but I dont know how I would make it add the button push counter, would this do it?

No. You still have no code to check for changes to the button state and incrementing the push count. It still stays at zero forever. Since zero is not equal to 1, 2, 3, or 4 then none of the 'if' statements will do anything.

I really have no more ideas...

#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
const int mypulsebase =  (1000);
const int pulseIncrement = (250);
const int myPulsetime =  mypulsebase;


int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonPushCounter % 1 == 0) {
    m1.attach(9);
    m1.writeMicroseconds(myPulsetime + pulseIncrement);
    delay(1);
  } else {
    m1.writeMicroseconds(1000);
    delay(1);



    if (buttonPushCounter % 2 == 0) {
      m1.attach(9);
      m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement);
      delay(1);
    } else {
      m1.writeMicroseconds(1000);
      delay(1);



      if (buttonPushCounter % 3 == 0) {
        m1.attach(9);
        m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement);
        delay(1);
      } else {
        m1.writeMicroseconds(1000);
        delay(1);


        if (buttonPushCounter % 4 == 0) {
          m1.attach(9);
          m1.writeMicroseconds(myPulsetime + pulseIncrement + pulseIncrement + pulseIncrement + pulseIncrement);
          delay(1);
        } else {
          m1.writeMicroseconds(1000);
          delay(1);





        }
      }
    }
  }
}

I really have no more ideas...

You need to know whether the button has become pressed since the last time that you looked at its state.

To do this you need a variable to hold the state the last time it was checked. You have one. It is named lastButtonState. You also need a variable to hold the state now. You have one. It is named buttonState. They are both global variables and both start off being zero.

You need to know what state the button pin is when the button is not pressed. The easy way to do this is to set the pin's state to INPUT_PULLUP using pinMode rather than just INPUT. This causes the pin to be normally kept HIGH. Arrange your wiring to take the pin to GND when the button is pressed. So, when the button is not pressed the pins state will be HIGH and when it is pressed it will be LOW.

Now, each time through loop() read the state of the pin putting the result in buttonState. Compare it with lastButtonState and if they are the same then nothing has changed. However, if they are different then either the button was pressed or released. Test the value of buttonState. If it is LOW then the button has become pressed since last checked. so let's act on it by adding 1 to buttonPushCounter. Whether or not the button has become pressed copy the value of buttonState to lastButtonState ready to check for changes next time through loop()

The result of this is that you have added 1 to buttonPushCounter when the button became pressed and you can use its value to decide what to do. There is a neater way to test its value and decide what to do but get your long winded version working first.