I dont know anything abouth arduino as you can see
This is the program:
#include <AFMotor.h>
const int analogPin = A0;
int data = 2;
AF_DCMotor motor(1);
AF_DCMotor motor(2);
void setup()
{
Serial.begin(9600);
motor.setSpeed(150);
}
void loop()
{
data = analogRead(analogPin);
if (data >= 200)
{
motor.run(FORWARD);
delay(10000);
motor.run(RELEASE);
}
else
{
motor.run(RELEASE);
}
This is the error:
Arduino:1.6.8 (Windows 10), Cart:"Arduino/Genuino Uno"
sketch_may07b:6: error: redefinition of 'AF_DCMotor motor'
AF_DCMotor motor(2);
^
sketch_may07b:5: error: 'AF_DCMotor motor' previously declared here
AF_DCMotor motor(1);
^
C:\Users\bepo-san\AppData\Local\Temp\arduino_modified_sketch_417087\sketch_may07b.ino: In function 'void loop()':
sketch_may07b:25: error: expected '}' at end of input
}
^
exit status 1
redefinition of 'AF_DCMotor motor'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
properly format your code an you may see the error:
Highlight all the text in the IDE
Select Tools > AutoFormat
No need to highlight the text in the IDE, just hit Ctrl/T
It did not work. Can you help me?
Bepo-san:
can you help me?
yes.
Re-post your code now that it is auto-formatted.
#include <AFMotor.h>
const int analogPin = A0;
int data = 2;
AF_DCMotor motor(1);
AF_DCMotor motor(2);
void setup()
{
Serial.begin(9600);
motor.setSpeed(150);
}
void loop()
{
data = analogRead(analogPin);
if (data >= 200)
{
motor.run(FORWARD);
delay(10000);
motor.run(RELEASE);
}
else
{
motor.run(RELEASE);
}
But it is same.
Here is your code in code tags
#include <AFMotor.h>
const int analogPin = A0;
int data = 2;
AF_DCMotor motor(1);
AF_DCMotor motor(2);
void setup()
{
Serial.begin(9600);
motor.setSpeed(150);
}
void loop()
{
data = analogRead(analogPin);
if (data >= 200)
{
motor.run(FORWARD);
delay(10000);
motor.run(RELEASE);
}
else
{
motor.run(RELEASE);
}
Note that the final brace is not on the left margin. Where is the end of the loop() function ?
Can you please post the full error message ?
How many tabs have you got in the IDE ?
Arduino:1.6.8 (Windows 10), Kart:"Arduino/Genuino Uno"
Derleme seçenekleri değiştirildi, tümü yeniden derleniyor.
sketch_may07b:6: error: redefinition of 'AF_DCMotor motor'
AF_DCMotor motor(2);
^
sketch_may07b:5: error: 'AF_DCMotor motor' previously declared here
AF_DCMotor motor(1);
^
C:\Users\bepo-san\AppData\Local\Temp\arduino_modified_sketch_300182\sketch_may07b.ino: In function 'void loop()':
sketch_may07b:25: error: expected '}' at end of input
}
^
exit status 1
redefinition of 'AF_DCMotor motor'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
My conclusion is that you have no closing brace at the end of the loop() function and more than one object named motor.
Add the closing brace and remove one of the instances of AF_DCMotor.
thanks it worked but i need 2 motors
How can we do this without error?
Bepo-san:
How can we do this without error?
you will need to learn and understand what you are doing, I'm afraid.
Use some thing like
AF_DCMotor motorOne(1);
AF_DCMotor motorTwo(2);
And maybe get a book on C.
How can we run 2 motors without errors i sad. What did you intend?
OK. It is working now. Thanks a lot guys.
if your code makes in the new installation Arduino IDE.
The direct and easy solution you mush change your filename code