[Edit - moderator - Please use the 'code' button when submitting code]
- Code: Select all
#include <AFMotor.h>
AF_DCMotor motor1(3, MOTOR12_64KHZ);// create motor #2, 64KHz pwm
AF_DCMotor motor2(4,MOTOR12_64KHZ);
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);
}
void loop() {
Serial.print("Ahead");
motor1.run(FORWARD); // turn it on going forward
motor2.run(FORWARD);
delay(5000);
Serial.print("Stop");
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(1000);
Serial.print("Turn");
motor1.run(FORWARD);
motor2.run(BACKWARD);
delay(1500);
Serial.print("Stop");
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(1000);
motor1.run(FORWARD); // turn it on going forward
motor2.run(FORWARD);
delay(5000);
Serial.print("Stop");
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(1000);
Serial.print("astern");
motor1.run(BACKWARD); // the other way
motor2.run(BACKWARD);
delay(4000);
Serial.print("Stop");
motor1.run(RELEASE); // stopped
motor2.run(RELEASE);
delay(1000);
Serial.print("Turn");
motor1.run(FORWARD);
motor2.run(BACKWARD);
delay(1500);
Serial.print("Stop");
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(2000);
motor1.run(FORWARD); // turn it on going forward
motor2.run(FORWARD);
delay(5000);
Serial.print("Stop");
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(1000);
Serial.print("TurnOpp");
motor1.run(BACKWARD);
motor2.run(FORWARD);
delay(1500);
Serial.print("Stop");
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(1000);
motor1.run(FORWARD); // turn it on going forward
motor2.run(FORWARD);
delay(5000);
Serial.print("Stop");
motor1.run(RELEASE);
motor2.run(RELEASE);
delay(3000);
}

