0

Heres the code

#include <AFMotor.h>

AF_DCMotor motor(1, MOTOR12_8KHZ);
AF_DCMotor motor(2, MOTOR12_8KHZ);
AF_DCMotor motor(3, MOTOR34_1KHZ);

void setup()  {
  Serial.begin(9600);
  Serial.printIn("Motor Test!");
  motor1.setSpeed(15); //set speed of motor
  motor2.setSpeed(15); //set speed of motor
  motor3.setSpeed(15); //set speed of motor

}
void loop() {
  Serial.print("tick");
  motor1.run(FORWARD);
  delay(2000);

  Serial.print("tock");
  motor1.run(RELEASE);
  delay(5000);

  Serial.print("tack"); //first song starts 
  motor1.run(BACKWARD);
  delay(2000);


  Serial.print("tock");
  motor1.run(RELEASE);
  delay(9000);

  Serial.print("tack"); 
  motor1.run(BACKWARD);
  delay(2000);

  Serial.print("tock"); //first song ends
  motor1.run(RELEASE);
  delay(20000);

  Serial.print("tick");
  motor1.run(FORWARD);
  delay(2000);

  Serial.print("tick"); 
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(5000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor1.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(FORWARD);
  delay(1000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor1.run(BACKWARD);
  delay(2000);

  Serial.print("tock");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(BACKWARD);
  delay(2000);

   Serial.print("tock");
  motor2.run(FORWARD);
  delay(1000);

  Serial.print("tick");
  motor2.run(RELEASE);
  delay(1000);

  Serial.print("tick");
  motor2.run(FORWARD);
  delay(2000);

  Serial.print("tack"); 
  motor1.run(BACKWARD);
  delay(2000);

  Serial.print("tock"); //first song stops
  motor2.run(RELEASE);
  delay(14000);

  Serial.print("tock"); //first song stops
  motor3.run(RELEASE);
  delay(11000);

  Serial.print("tick"); //first song stops
  motor3.run(FORWARD);
  delay(22000);

  Serial.print("tock"); //first song stops
  motor3.run(RELEASE);
  delay(19000);
}

Here is the error:

   ^~~~~~

   motor

snowmanDC_Motor:13:3: error: 'motor3' was not declared in this scope

   motor3.setSpeed(15); //set speed of motor

   ^~~~~~

C:\Users\serluca\Documents\Arduino\snowmanDC_Motor\snowmanDC_Motor.ino:13:3: note: suggested alternative: 'motor'

   motor3.setSpeed(15); //set speed of motor

   ^~~~~~

   motor

C:\Users\serluca\Documents\Arduino\snowmanDC_Motor\snowmanDC_Motor.ino: In function 'void loop()':

snowmanDC_Motor:18:3: error: 'motor1' was not declared in this scope

   motor1.run(FORWARD);

   ^~~~~~

C:\Users\serluca\Documents\Arduino\snowmanDC_Motor\snowmanDC_Motor.ino:18:3: note: suggested alternative: 'motor'

   motor1.run(FORWARD);

   ^~~~~~

   motor

snowmanDC_Motor:47:3: error: 'motor2' was not declared in this scope

   motor2.run(FORWARD);

   ^~~~~~

C:\Users\serluca\Documents\Arduino\snowmanDC_Motor\snowmanDC_Motor.ino:47:3: note: suggested alternative: 'motor'

   motor2.run(FORWARD);

   ^~~~~~

   motor

snowmanDC_Motor:115:3: error: 'motor3' was not declared in this scope

   motor3.run(RELEASE);

   ^~~~~~

C:\Users\serluca\Documents\Arduino\snowmanDC_Motor\snowmanDC_Motor.ino:115:3: note: suggested alternative: 'motor'

   motor3.run(RELEASE);

   ^~~~~~

   motor

exit status 1
redefinition of 'AF_DCMotor motor'
4
  • 1
    Do you have V1 or V2 shield? They have different library. – Fahad Apr 1 '20 at 1:58
  • 1
    @Tommy, you are still at it ... congratulations for not giving up .... I can tell you right now, you will have a long battle until you tell us what hardware you have and how you connected it – jsotola Apr 1 '20 at 5:02
  • 1
    You consistently fail to use libraries that you have installed. Or you are sure you have installed. Instead of repeatedly throwing the same code at us with a different library you should instead take a step back and look more into how you are going about installing libraries and why, maybe, the IDE can't find them. arduino.cc/en/guide/libraries – Majenko Apr 1 '20 at 10:31
  • Comments are not for extended discussion; this conversation has been moved to chat. – VE7JRO Apr 1 '20 at 23:47
1

Adafruit has a V1 and a V2 motor shield. They have different libraries too. AFMotor.h is for the V1 shield. From the error, I can tell you installed V2 lib. For that you need to include:

#include <Adafruit_MotorShield.h> 
3
  • I needed to install the Adafruit v1 library Thanks for the help tho, Im new to all of this stuff. but now its saying another error "redefinition of 'AF_DCMotor' – Tommy Apr 1 '20 at 12:38
  • I fixed the question to the new question, the new error is in there too – Tommy Apr 1 '20 at 17:39
  • On line 3,4, and 5, you used same name "motor" for all three instances. Changed those to motor1, motor2, and motor3 – Fahad Apr 2 '20 at 3:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.