I found one way of solving this problem on my adafruit sheild. heres what I fumbled together so far.
#include <AFMotor.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
//2.Create the AF_DCMotor object with AF_DCMotor(motor#, frequency), to setup the motor H-bridge and latches. The constructor takes two arguments.
//The first is which port the motor is connected to, 1, 2, 3 or 4.
//frequency is how fast the speed controlling signal is.
//For motors 1 and 2 you can choose MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_2KHZ, or MOTOR12_1KHZ. A high speed like 64KHz wont be audible but a low speed like 1KHz will use less power. Motors 3 & 4 are only possible to run at 1KHz and will ignore any setting given
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
motor1.setSpeed(200); // set the speed to 200/255
motor2.setSpeed(200); // set the speed to 200/255
}
void loop() {
Serial.print("tick");
motor1.run(FORWARD);
motor2.run(FORWARD); // turn it on going forward
delay(10000);
motor1.run(FORWARD);
motor2.setSpeed(100);
motor2.run(FORWARD); // turn it on going forward
delay(10000);
motor1.run(FORWARD);
motor2.setSpeed(200);
motor2.run(FORWARD); // turn it on going forward
delay(10000);
motor1.run(FORWARD);
motor2.setSpeed(100);
motor2.run(FORWARD); // turn it on going forward
delay(10000);
Serial.print("tack");
motor1.run(RELEASE);
motor2.run(RELEASE); // stopped
delay(10000);
motor1.run(FORWARD);
motor2.run(FORWARD); // turn it on going forward
delay(10000);
motor1.run(FORWARD);
motor2.run(FORWARD); // turn it on going forward
delay(10000);
Serial.print("tock");
motor1.run(BACKWARD);
motor2.run(BACKWARD); // the other way
delay(10000);
Serial.print("tack");
motor1.run(RELEASE);
motor2.run(RELEASE); // stopped
delay(10000);
}
thats a long loop but I hope you get the idea.