Code Example

#include <AFMotor.h>

AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor3(3, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
void setup() {
  motor2.setSpeed(250);     // set the speed to 200/255
  motor3.setSpeed(170);     // set the speed to 200/255
  delay(3000);  //Chill a bit before motors start
}
void f(int d) { // Call Forward
  motor3.run(FORWARD);      // turn it on going forward
  motor2.run(FORWARD);      // turn it on going forward
  delay(d);
}

void b(int d) { // Call Backup
  motor3.run(BACKWARD);     // the other way
  motor2.run(BACKWARD);     // the other way
  delay(d);
}

void r(int d) { // Call Turn Right
  motor3.run(BACKWARD);      // turn it on going reverse
  motor2.run(FORWARD);      // turn it on going forward
  delay(d);
}

void l(int d) { // Call Turn Left
  motor3.run(FORWARD);      // turn it on going forward
  motor2.run(BACKWARD);      // turn it on going reverse
  delay(d);
}

void s(int d) { // Call Stop
  motor2.run(RELEASE);      // stopped
  motor3.run(RELEASE);      // stopped
  delay(d);
}

void loop() {
  
f(1000);
r(1000);
l(1000);
s(1000);
b(1000);
s(1000);
 while (true);
}