using pullstime

As you can see buttonPushCounter % 5 produces a number between 0 and 5

So you could use this value to set what you write to m1 like this

byte index = buttonPushCounter % 5;
if (index == 0)
  {
     m1.writeMicroseconds(something);
  }
else if (index == 1)
  {
     m1.writeMicroseconds(somethingElse);
  }
else if (index == 2)
  {
     m1.writeMicroseconds(anotherValue);
  }

Try that and get it working then I will suggest an even better way to do it

Compiles, no error

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

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_PULLUP);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

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

  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println(buttonPushCounter);
      Serial.print("buttonPushCounter % 5 = ");
      Serial.println(buttonPushCounter % 5);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }

  lastButtonState = buttonState;

  {
    byte index = buttonPushCounter % 5;
    if (index == 0)
    {
      m1.writeMicroseconds(1000);
    }
    else if (index == 1)
    {
      m1.writeMicroseconds(1250);
    }
    else if (index == 2)
    {
      m1.writeMicroseconds(1500);
    }
    else if (index == 3)
    {
      m1.writeMicroseconds(1750);
    }
      else if (index == 4)
      {
        m1.writeMicroseconds(2000);
      }
  }
}
pinMode(buttonPin, INPUT_PULLUP);
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<

That code's actually counting releases. With pullups enabled, pressed is low, yet you're looking for a high after a change, which is a release not a press.

everything is working what now?

Well every press has a release, so if you count releases that's numerically the same as counting presses, but it's not strictly a buttonPushCounter, it's a buttonReleaseCounter.

This whole set of nested ifs:-

{
    byte index = buttonPushCounter % 5;
    if (index == 0)
    {
      m1.writeMicroseconds(1000);
    }
    else if (index == 1)
    {
      m1.writeMicroseconds(1250);
    }
    else if (index == 2)
    {
      m1.writeMicroseconds(1500);
    }
    else if (index == 3)
    {
      m1.writeMicroseconds(1750);
    }
      else if (index == 4)
      {
        m1.writeMicroseconds(2000);
      }
  }

Can be replaced with two lines of code:-

byte index = buttonPushCounter % 5;
m1.writeMicroseconds(1000 + (index * 250);

To explain it fully buttonPushCounter % 5 returns either 0, 1, 2, 3 or 4 to index therefore you have the following microsecond values written to m1:-

If index = 0, index * 250 is 0 so 1000 is written to m1.
If index = 1, index * 250 is 250 so 1250 is written to m1.
If index = 2, index * 250 is 500 so 1500 is written to m1.
If index = 3, index * 250 is 750 so 1750 is written to m1.
If index = 4, index * 250 is 100 so 2000 is written to m1.

Much simpler than a whole pile of nested ifs.

Ian

IanCrowe:
Much simpler than a whole pile of nested ifs.

Perhaps that's what this was going to be:

UKHeliBob:
Try that and get it working then I will suggest an even better way to do it

@IanCrowe, I think UKHeliBob has a plan here: he's walked this OP through a process for a couple of days now, and with all due respect to the OP, he (the OP) is struggling, and perhaps it would be better to leave UKHB to it....

(I've been here since #5, and just chipped in with parts where I saw errors, like the x%0 thing and the counting of releases not presses. Your suggestion is of course a very valid one, I just think it's best to let UKHB go with this... (imo, of course.))

Matyk:
everything is working what now?

Now we move on to reducing your code by using the number in the index variable to do some "magic"

As you have seen you can use it to calculate the value to write to m1 and that is one option that I had considered suggesting, and it works but the relationship between the number of button presses and the value written is fixed which may not always be what is wanted and it required the Arduino to do the caculation each time through loop()

I was going to suggest using an array of values to be written to m1 based on the value of index.

For the sake of Matyk, an array is a way of holding a list of several values of the same type and accessing the one you want using its place in the list. The index variable gives us a convenient way to access the required value.

So, how does it work ?
Declare a global array of ints like this

int writeValues[5] = {123, 234, 345, 456, 567};  //fill in the values that you really want

NOTE: This array has 5 spaces numbered 0 to 4 NOT 1 to 5

Then, once you have the value of index you can do
m1.writeMicroseconds(writeValues[index]);

This uses index to look up the value to write. Because you have control of the values in the array the value written for each button press is fully under your control and does not need to be linear.

Give both methods a try

I tried both methods both compile, serial monitor looks fine but the still don't do anything. Is it still in the program?

#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
int writeValues[5] = {1000, 1250,1500,1750,2000}; 
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_PULLUP);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

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

  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println(buttonPushCounter);
      Serial.print("buttonPushCounter % 5 = ");
      Serial.println(buttonPushCounter % 5);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }

  lastButtonState = buttonState;

  {
  if (buttonState == LOW); 
  m1.writeMicroseconds(writeValues[5]);
  }
}
#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;

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_PULLUP);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

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

   if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
     Serial.println(buttonPushCounter);
      Serial.print("buttonPushCounter % 5 = ");
      Serial.println(buttonPushCounter % 5);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;
  
  {
  if (buttonState == HIGH);
  byte index = buttonPushCounter % 5;
  m1.writeMicroseconds(1000 + (index * 250));

    }
  }
    if (buttonState == LOW);
    m1.writeMicroseconds(writeValues[5]);

Three things wrong here

1 - the if is terminated by a semicolon. The semicolon is the only code whose execution depends on whether the if test returns true. Remove it

2 - the array entry 5 does not exist. The array values are numbered 0 to 4 as I warned you in an earlier post

3 - you are meant to use the value of buttonPushCounter % 5 as the array index to select the correct value for the value to write to m1.

oh wait so would I do it like this, for every value...

{
if (buttonState == LOW)
m1.writeMicroseconds(writeValues[0]);
}

{
if (buttonState == LOW)
m1.writeMicroseconds(writeValues[1]);
}

{
if (buttonState == LOW)
m1.writeMicroseconds(writeValues[2]);
}

{
if (buttonState == LOW)
m1.writeMicroseconds(writeValues[3]);
}

{
if (buttonState == LOW)
m1.writeMicroseconds(writeValues[4]);
}
}

sorry wrong thing...

{
  if (buttonState == LOW)
  m1.writeMicroseconds(writeValues[0]);
  }

  {
  if (buttonState == LOW)
  m1.writeMicroseconds(writeValues[1]);
  }

  {
  if (buttonState == LOW)
  m1.writeMicroseconds(writeValues[2]);
  }

  {
  if (buttonState == LOW)
  m1.writeMicroseconds(writeValues[3]);
  }

  {
  if (buttonState == LOW)
  m1.writeMicroseconds(writeValues[4]);
  }
}

NO, NO, NO NO !

You have an array of 5 values numbered from 0 to 4

int writeValues[5] = {1000, 1250,1500,1750,2000};

You have a number between 0 and 4 derived like this

buttonPushCounter % 5)

You do not need to test its value 5 times. Instead you use its value to select the associated value from the array like this

m1.writeMicroseconds(writeValues[buttonPushCounter % 5)]);
#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
int writeValues[5] = {1000, 1250,1500,1750,2000}; 
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_PULLUP);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

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

  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println(buttonPushCounter);
      Serial.print("buttonPushCounter % 5 = ");
      Serial.println(buttonPushCounter % 5);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }

  lastButtonState = buttonState;

  {
  m1.writeMicroseconds(writeValues[buttonPushCounter % 5]);
  }
}

Does it work ?

I can't test it right now...

Is it the f***in code again?

#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
int writeValues[5] = {1000, 1250,1500,1750,2000}; 
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_PULLUP);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

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

  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println(buttonPushCounter);
      Serial.print("buttonPushCounter % 5 = ");
      Serial.println(buttonPushCounter % 5);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }

  lastButtonState = buttonState;

  {
  m1.writeMicroseconds(writeValues[buttonPushCounter % 5]);
  }
}

Is what in the code ?

You forgot to do the m1.attach() in setup()

oh the message didn't send itself, well basically I now can't upload the code to the Arduino.

Sketch uses 3268 bytes (10%) of program storage space. Maximum is 32256 bytes.
Global variables use 273 bytes (13%) of dynamic memory, leaving 1775 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

I now can't upload the code to the Arduino.

That is not a problem with the code. Close down the IDE, unplug the Arduino then restart the IDE and plug the Arduino back in and check that the COM port that it is using is correct.