I have written a code speeds up one motor and then a second motor but I would really like them to do this simultaneously as opposed to one after another. What would be the best method to accomplish this?
#include <Adafruit_MotorShield.h>
#include <Wire.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(3);
void setup()
{
AFMS.begin();
myMotor->setSpeed(150);
myMotor->run(FORWARD);
myMotor->run(RELEASE);
myMotor2->setSpeed(150);
myMotor2->run(FORWARD);
myMotor2->run(RELEASE);
}
void loop()
{
uint8_t i;
myMotor->run(FORWARD);
for (i=0; i<255; i++)
{
myMotor->setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--)
{
myMotor->setSpeed(i);
myMotor->setSpeed(i);
delay(10);
}
uint8_t h;
myMotor2->run(BACKWARD);
for (h=0; h<255; h++)
{
myMotor2->setSpeed(h);
delay(10);
}
for (h=255; h!=0; h--)
{
myMotor2->setSpeed(h);
delay(10);
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.