using pullstime

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


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.write myPulsetime = (myPulseTime + pulseIncrement);
    delay(1);
  } else {
    m1.writeMicroseconds(1000);
    delay(1);



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



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





      }
    }
  }
}

Matyk:
Thanks so much, everything is working, but the damn thing is now saying: expected ';' before 'myPulsetime'
at the last segment ( the part before the special symbols).

It can't be working if you are still getting errors while compiling

Post the code as it is now and the full error message

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

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.write myPulsetime = (mypulseTime + pulseIncrement);
delay(1);
} else {
m1.writeMicroseconds(1000);
delay(1);

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

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

}
}
}
}

Arduino: 1.8.7 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/matyaskloc/Desktop/ESC-ARDUINO-CONTROL/ANother_one/ANother_one.ino: In function 'void loop()':
ANother_one:29:14: error: expected ';' before 'myPulsetime'
m1.write myPulsetime = (mypulseTime + pulseIncrement);
^
ANother_one:29:58: error: invalid use of non-static member function
m1.write myPulsetime = (mypulseTime + pulseIncrement);
^
ANother_one:39:16: error: expected ';' before 'myPulsetime'
m1.write myPulsetime = (mypulseTime + pulseIncrement);
^
ANother_one:39:60: error: invalid use of non-static member function
m1.write myPulsetime = (mypulseTime + pulseIncrement);
^
ANother_one:49:18: error: expected ';' before 'myPulsetime'
m1.write myPulsetime = (mypulseTime + pulseIncrement)
^
ANother_one:50:17: error: invalid use of non-static member function
delay(1);
^
exit status 1
expected ';' before 'myPulsetime'

    m1.write myPulsetime = (mypulseTime + pulseIncrement);

What are you trying to write to the servo ?

Servos and ESCs get the same kind of signal, 50Hz signal. The pulse signal varies from 1ms to 2ms, with 1ms represents the motor off completely and 2ms is the maximum speed and anything between is also varying speed.
so technically what I am trying to do is, for the first press of the button the signal would be 1500 (1250+250) so middle speed, second press it would be 1750 (1500+250) 3/4 of the max speed and for the third click, it would be 2000 (1750+250).

This should do what you want (or close to it) if you add the missing code to increment 'buttonPushCounter' when the button is pushed.

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

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


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);

  m1.attach(9);
}

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

  switch (buttonPushCounter)
  {
    case 1:  // First push: 1/2 speed
      myPulseTime = PulseTimeBase + PulseTimeIncrement;
      break;

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

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

    default:  // 1/4 speed and reset the push counter
      buttonPushCounter = 0;
      myPulseTime = PulseTimeBase;
      break;
  }

  m1.writeMicroseconds(myPulseTime );
}

Matyk:
Servos and ESCs get the same kind of signal, 50Hz signal. The pulse signal varies from 1ms to 2ms, with 1ms represents the motor off completely and 2ms is the maximum speed and anything between is also varying speed.
so technically what I am trying to do is, for the first press of the button the signal would be 1500 (1250+250) so middle speed, second press it would be 1750 (1500+250) 3/4 of the max speed and for the third click, it would be 2000 (1750+250).

I am familiar with and understand all that and in your code you have instances of writing correctly to m1 like this

   m1.writeMicroseconds(1000);

So why in other places in the code do you use the write() function like this ?

       m1.write myPulsetime = (mypulseTime +  pulseIncrement);

which is so obviously different

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 (the thing is that can't have a potentiometer because this project is going underwater, so I just wanted 1 button that would vary through 3 speeds) I put the m1.write because I didn't know what function or whatever I should use.

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;