Need help with switches controlling stepper motor

I have the following code that seems to work fine except that the motor makes multiple steps when I press the switches attached to A3 and A4.

#include <AFMotor.h>
AF_Stepper motor(200, 1); // 200 turns/revolution on Channel 1
void setup() {
Serial.begin(9600);

motor.setSpeed(25); // set motor speed to 25 RPM

int switchPin = A0; // set A0 as switch pin
int switchPin2 = A1; // set A1 as switch pin
int switchPin3 = A2; // set A2 as switch pin
int switchPin4 = A3; // set A3 as switch pin
int switchPin5 = A4; // set A4 as switch pin
int switchPin6 = A5; // set A5 as switch pin

pinMode(switchPin, INPUT); // set Pin A0 as an input
pinMode(switchPin2, INPUT); // set Pin A1 as an input
pinMode(switchPin3, INPUT); // set Pin A2 as an input
pinMode(switchPin4, INPUT); // set Pin A3 as an input
pinMode(switchPin5, INPUT); // set Pin A4 as an input
pinMode(switchPin6, INPUT); // set Pin A5 as an input

digitalWrite(switchPin, HIGH); // use pull up resistors for all switch pins
digitalWrite(switchPin2, HIGH);
digitalWrite(switchPin3, HIGH);
digitalWrite(switchPin4, HIGH);
digitalWrite(switchPin5, HIGH);
digitalWrite(switchPin6, HIGH);
motor.release();

}
void loop() {
motor.release();

while (digitalRead(A0) == LOW)

motor.step(88, FORWARD, INTERLEAVE);
delay(10);

while (digitalRead(A1) == LOW)

motor.step(100, FORWARD, INTERLEAVE);
delay(10);

while (digitalRead(A2) == LOW)

motor.step(112, FORWARD, INTERLEAVE);
delay(10);

while (digitalRead(A3) == LOW)

motor.step(1, BACKWARD, INTERLEAVE);
delay(10);

if (digitalRead(A4) == LOW)

motor.step(1, FORWARD, INTERLEAVE);
delay(10);

if (digitalRead(A5) == LOW)

motor.step(100, BACKWARD, INTERLEAVE);
delay(10);

}

You are not doing anything to de-bounce the switches.
So everytime you press a mechanical buttom, it will look like 0011001010101010100000 until settles.
And the same when you releaseit 101001101111111 until it settles.
Hence multiple steps.

Why did you switch from this format
while (digitalRead(A3) == LOW)

to this format
if (digitalRead(A4) == LOW)

for A4 & A5?

Also, you went to the trouble of define all the switchPins, then you called out Ax in void loop?

Thanks for the reply.

  1. I figured I needed to debounce in some way but am not familiar with how to do it.

  2. No particular reason for the change from "While" to "If". Just found that it seems to take fewer multiples using "If". The other larger steps react the same either way.

  3. Not sure what you are saying here. Did I duplicate something?

  // Here, you give it a name
  int switchPin = A0;                  // set A0 as switch pin
//here, you ignore the name
while (digitalRead(A0) == LOW)

Do some reading here to smooth out your button presses