I was wondering if there was anyway to drive multiple motors simultaneously with the Adafruit Motor Shield v2(https://www.adafruit.com/products/1438). Specifically, I am trying to drive 2 Servos, 1 DC Motor, and one Uni-polar Stepper simultaneously, but no matter what I try I can't seem to get all the motors to run at once. Any response is much appreciated. The code I am currently using is below, it does all of the functions one right after another:
Code: Select all
#include <Wire.h>
#include <Servo.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h";
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor*dcMotor = AFMS.getMotor(2);
Adafruit_StepperMotor*myMotor = AFMS.getStepper(200, 2);
Servo servo1;
Servo servo2;
int i;
int x;
void setup() {
AFMS.begin();
myMotor->setSpeed(30);
dcMotor->setSpeed(150);
servo1.attach(10);
servo2.attach(9);
}
void loop() {
myMotor->step(400, FORWARD, DOUBLE);
myMotor->step(400, BACKWARD, DOUBLE);
dcMotor->run(FORWARD);
delay(5000);
dcMotor->run(RELEASE);
delay(1000);
dcMotor->run(BACKWARD);
delay(5000);
dcMotor->run(RELEASE);
delay(1000);
for (i = 0, x = 180; i <= 180, x >= 0; i++, x--) {
servo1.write(i);
servo2.write(x);
delay(10);
}
for (i = 180, x = 0; i >= 0, x <= 180; i--, x++) {
servo1.write(i);
servo2.write(x);
delay(10);
}
}