Hi. I am new in arduino and I am trying to build a robot with arduino leonardo. I have a motor shield , Aihasd l293d motor drive shield. I download the AFMotor.h library, but when i compile the sketch I have some errors about the library. I don?t know what to do. someone help me?
In file included from c:\users\danie\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\io.h:99:0,
from c:\users\danie\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\pgmspace.h:90,
from C:\Users\danie\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/Arduino.h:28,
from C:\Users\danie\AppData\Local\Temp\arduino\sketches\D7B9A865359F9D7C30AC03C74F983471\sketch\MotorTest4wd.ino.cpp:1:
C:\Users\danie\Documents\Arduino\libraries\Adafruit_Motor_Shield_library/AFMotor.h:46:30: error: 'CS22' was not declared in this scope
#define MOTOR12_1KHZ _BV(CS22) // divide by 64
^
C:\Users\danie\Downloads\MotorTest4wd\MotorTest4wd.ino:15:31: note: in expansion of macro 'MOTOR12_1KHZ'
AF_DCMotor Motor_Left_Rear(1, MOTOR12_1KHZ); // Motor 1
^~~~~~~~~~~~
C:\Users\danie\Documents\Arduino\libraries\Adafruit_Motor_Shield_library/AFMotor.h:46:30: note: suggested alternative: 'CS12'
#define MOTOR12_1KHZ _BV(CS22) // divide by 64
^
C:\Users\danie\Downloads\MotorTest4wd\MotorTest4wd.ino:15:31: note: in expansion of macro 'MOTOR12_1KHZ'
AF_DCMotor Motor_Left_Rear(1, MOTOR12_1KHZ); // Motor 1
^~~~~~~~~~~~
C:\Users\danie\Documents\Arduino\libraries\Adafruit_Motor_Shield_library/AFMotor.h:46:30: error: 'CS22' was not declared in this scope
#define MOTOR12_1KHZ _BV(CS22) // divide by 64
^
C:\Users\danie\Downloads\MotorTest4wd\MotorTest4wd.ino:16:32: note: in expansion of macro 'MOTOR12_1KHZ'
AF_DCMotor Motor_Right_Rear(2, MOTOR12_1KHZ); // Motor 2
^~~~~~~~~~~~
C:\Users\danie\Documents\Arduino\libraries\Adafruit_Motor_Shield_library/AFMotor.h:46:30: note: suggested alternative: 'CS12'
#define MOTOR12_1KHZ _BV(CS22) // divide by 64
^
C:\Users\danie\Downloads\MotorTest4wd\MotorTest4wd.ino:16:32: note: in expansion of macro 'MOTOR12_1KHZ'
AF_DCMotor Motor_Right_Rear(2, MOTOR12_1KHZ); // Motor 2
^~~~~~~~~~~~
exit status 1
Compilation error: exit status 1
The sketch is
const int LED_PIN = 13;
const int speed = 60; // percent of maximum speed
#include <AFMotor.h> // adafruit motor shield library (modified my mm)
AF_DCMotor Motor_Left_Front(4, MOTOR34_1KHZ); // Motor 4
AF_DCMotor Motor_Right_Front(3, MOTOR34_1KHZ); // Motor 3
AF_DCMotor Motor_Left_Rear(1, MOTOR12_1KHZ); // Motor 1
AF_DCMotor Motor_Right_Rear(2, MOTOR12_1KHZ); // Motor 2
int pwm;
void setup() {
Serial.begin(9600);
blinkNumber(8); // open port while flashing. Needed for Leonardo only
// scale percent into pwm range (0-255)
pwm = map(speed, 0, 100, 0, 255);
Motor_Left_Front.setSpeed(pwm);
Motor_Right_Front.setSpeed(pwm);
Motor_Left_Rear.setSpeed(pwm);
Motor_Right_Rear.setSpeed(pwm);
}
// run over and over
void loop() {
Serial.println("rotate cw");
Motor_Left_Front.run(FORWARD);
Motor_Left_Rear.run(FORWARD);
Motor_Right_Front.run(BACKWARD);
Motor_Right_Rear.run(BACKWARD);
delay(5000); // run for 5 seconds
Serial.println("stopped");
Motor_Left_Front.run(RELEASE); // stop the motors
Motor_Right_Front.run(RELEASE);
Motor_Left_Rear.run(RELEASE); // stop the motors
Motor_Right_Rear.run(RELEASE);
delay(5000); // stop for 5 seconds
}
// function to indicate numbers by flashing the built-in LED
void blinkNumber(byte number) {
pinMode(LED_PIN, OUTPUT); // enable the LED pin for output
while (number--) {
digitalWrite(LED_PIN, HIGH);
delay(100);
digitalWrite(LED_PIN, LOW);
delay(400);
}
}
[sterretje edit]
Code tags fixed
[sterretje end]