Im trying to make some stepper motors move with some motor shields on the press of a key but its not working. Can you tell me what i did wrong?
// calling librarys
#include <Keypad.h>
#include <Stepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
//Keypad
const int stepsPerRevolution = 200;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'#','0','*','D'}
};
byte rowPins[ROWS] = {0, 1, 2, 3};
byte colPins[COLS] = {4, 5, 6, 7};
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// Motor Shields
Adafruit_MotorShield AFMS1 = Adafruit_MotorShield();
Adafruit_MotorShield AFMS2 = Adafruit_MotorShield(0x61);
Adafruit_MotorShield AFMS3 = Adafruit_MotorShield(0x62);
Adafruit_MotorShield AFMS4 = Adafruit_MotorShield(0x63);
// Motors connected to shields
Adafruit_StepperMotor *myMotor1 = AFMS1.getStepper(200, 1);
Adafruit_StepperMotor *myMotor2 = AFMS1.getStepper(200, 2);
Adafruit_StepperMotor *myMotor3 = AFMS2.getStepper(200, 1);
Adafruit_StepperMotor *myMotor4 = AFMS2.getStepper(200, 2);
Adafruit_StepperMotor *myMotor5 = AFMS3.getStepper(200, 1);
Adafruit_StepperMotor *myMotor6 = AFMS3.getStepper(200, 2);
Adafruit_StepperMotor *myMotor7 = AFMS4.getStepper(200, 1);
Adafruit_StepperMotor *myMotor8 = AFMS4.getStepper(200, 2);
void setup() {
Serial.begin(9600);
Serial.println("Stepper test!");
AFMS1.begin();
AFMS2.begin();
AFMS3.begin();
AFMS4.begin();
myMotor1->setSpeed(100);
myMotor2->setSpeed(100);
myMotor3->setSpeed(100);
myMotor4->setSpeed(100);
myMotor5->setSpeed(100);
myMotor6->setSpeed(100);
myMotor7->setSpeed(100);
myMotor8->setSpeed(100);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey == '1'){
Serial.println(customKey);
Serial.println("clockwise");
myMotor1->step(100, FORWARD, DOUBLE);
}if (customKey == '2'){
Serial.println(customKey);
Serial.println("clockwise");
myMotor2->step(100, FORWARD, DOUBLE);
}if (customKey == '3'){
Serial.println(customKey);
Serial.println("clockwise");
myMotor3->step(100, FORWARD, DOUBLE);
}if (customKey == '4'){
Serial.println(customKey);
Serial.println("clockwise");
myMotor4->step(100, FORWARD, DOUBLE);
}if (customKey == '5'){
Serial.println(customKey);
Serial.println("clockwise");
myMotor5->step(100, FORWARD, DOUBLE);
}
if (customKey == '6'){
Serial.println(customKey);
Serial.println("clockwise");
myMotor6->step(100, FORWARD, DOUBLE);
}if (customKey == '7'){
Serial.println(customKey);
Serial.println("clockwise");
myMotor7->step(100, FORWARD, DOUBLE);
}if (customKey == '8'){
Serial.println(customKey);
Serial.println("clockwise");
myMotor8->step(100, FORWARD, DOUBLE);
}
}