I have a motor controller controlling two motors, which works perfectly fine when I comment out the two servos in the below code. These two servos are not connected to the motor controller but simply being operated using other Arduino Uno pins, as seen in the code.
When the servo attach()
functions are included in the code the motor controller only works with one of the motors and the other completely stops working.
I don't understand why the servos are interfering with the motor controller. What's going on here?
#include <Servo.h>
Servo myServo1;
Servo myServo2;
int m1_ALI = 10;
int m1_BLI = 9;
int m2_ALI = 3;
int m2_BLI = 11;
int m1_AHI = 12;
int m1_BHI = 4;
int m2_AHI = 6;
int m2_BHI = 5;
void setup() {
//myServo1.attach(7);
//myServo2.attach(8);
pinMode(m1_AHI, OUTPUT);
pinMode(m1_ALI, OUTPUT);
pinMode(m1_BLI, OUTPUT);
pinMode(m1_BHI, OUTPUT);
pinMode(m2_AHI, OUTPUT);
pinMode(m2_ALI, OUTPUT);
pinMode(m2_BLI, OUTPUT);
pinMode(m2_BHI, OUTPUT);
}
void loop() {
moveForward(30);
}//end loop
void moveForward(int x){
digitalWrite(m1_AHI, LOW);
digitalWrite(m1_BLI, LOW);
digitalWrite(m1_BHI, HIGH);
digitalWrite(m2_AHI, LOW);
digitalWrite(m2_BLI, LOW);
digitalWrite(m2_BHI, HIGH);
analogWrite(m2_ALI, x);
analogWrite(m1_ALI, x);
}//end moveForward