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