So, I have been doing some research to test out coding for two 5V hobby motors through a dual h-bridge Adafruit shield (connected to my Arduino Uno). Eventually, I would like to control each one separately so that the vehicle can turn (one motor per side on a tracked vehicle). While I have tried using different ways of coding from other posts, right now I am only getting one motor to run, but I’m not sure where I am going wrong. Do any of you see where I am lost (besides everywhere haha).
#include <AFMotor.h>
AF_DCMotor motor2(2);
AF_DCMotor motor4(4);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
// turn on motor
motor2.setSpeed(200);
motor4.setSpeed(200);
motor2.run(RELEASE);
motor4.run(RELEASE);
}
void loop() {
uint8_t i;
Serial.print("tick");
motor2.run(FORWARD);
for (i=0; i<255; i++) {
motor2.setSpeed(i);
motor4.setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
motor2.setSpeed(i);
motor4.setSpeed(i);
delay(10);
}
Serial.print("tock");
motor2.run(BACKWARD);
motor4.run(BACKWARD);
for (i=0; i<255; i++) {
motor2.setSpeed(i);
motor4.setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
motor2.setSpeed(i);
motor4.setSpeed(i);
delay(10);
}
Serial.print("tech");
motor2.run(RELEASE);
motor4.run(RELEASE);
delay(1000);
}