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 pinpinMode(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 inputdigitalWrite(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);}