Hey guys am trying to control one servo and two DC and a stepper motor simultaneously, but if the servo runs only one other DC motor runs and if the DC motors run then the servo does not run.I need them to be interleaved.Could someone help me out with a code example.
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
#include <AFMotor.h>
#include <Servo.h>
// DC motor on M2
AF_DCMotor motor(2);
AF_DCMotor motor1(1);
// DC hobby servo
Servo servo1;
// Stepper motor on M3+M4 48 steps per revolution
AF_Stepper stepper(48, 2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor party!");
motor1.setSpeed(200);
motor1.run(RELEASE);
// turn on servo
servo1.attach(9);
// turn on motor #2
motor.setSpeed(200);
motor.run(RELEASE);
}
int i;
// Test the DC motor, stepper and servo ALL AT ONCE!
void loop() {
motor.run(FORWARD);
for (i=0; i<255; i++) {
servo1.write(i);
motor.setSpeed(i);
stepper.step(1, FORWARD, INTERLEAVE);
delay(3);
motor1.setSpeed(i);
}
for (i=255; i!=0; i--) {
servo1.write(i-255);
motor.setSpeed(i);
stepper.step(1, BACKWARD, INTERLEAVE);
delay(3);
motor1.setSpeed(i);
}
motor.run(BACKWARD);
for (i=0; i<255; i++) {
servo1.write(i);
motor.setSpeed(i);
delay(3);
stepper.step(1, FORWARD, DOUBLE);
motor1.setSpeed(i);
}
for (i=255; i!=0; i--) {
servo1.write(i-255);
motor.setSpeed(i);
stepper.step(1, BACKWARD, DOUBLE);
delay(3);
motor1.setSpeed(i);
}
}