The AdaFruit motor shield associates Digital pin 3 with DC Motor #2 / Stepper #1 (activation/speed control).
I have built a robot using the Arduino Mega, AdaFruit Mega Shield, and AdaFruit Mega Shield and two DC motors. I used the Mega because I wanted to associate all bumper/cliff on/off switches with corresponding interrupts and needed as many interrupts as I could get.
When running, if pin 3 drops to zero, the right motor stops and the left motor starts and stops (steps?).
How can I manage some sort of compatibility or is this project doomed? Is there a Mega motor shield?
Stripped down code, involving only the motor running straight ahead and pin 3 (which I cannot seem to read) follows:
Code: Select all
// Sketch: motorCheck
// Robot running motor check.
#include <AFMotor.h>
AF_DCMotor rightMotor(1, MOTOR12_64KHZ); // Right wheel motor
AF_DCMotor leftMotor(2, MOTOR12_64KHZ); // Left wheel motor
const int defaultDelay = 20;
int leftCliffIntPin = 3;
void setup()
{
Serial.begin(9600); // start the serial port
Serial.print("FORWARD = "); Serial.println(FORWARD);
Serial.print("BACKWARD = "); Serial.println(BACKWARD);
// Install pull-up resistors on pin
pinMode(leftCliffIntPin, INPUT);
digitalWrite(leftCliffIntPin, HIGH);
// Start the motors
rightMotor.setSpeed(200);
leftMotor.setSpeed(200);
rightMotor.run(FORWARD);
leftMotor.run(BACKWARD);
}
void loop()
{
runStraight(defaultDelay);
int pinVal = digitalRead(leftCliffIntPin);
if (pinVal == HIGH) Serial.println("High, high, high");
else Serial.println("Low, low, low");
Serial.println("Running forward.");
}
void runStraight(int straightDelay)
{
rightMotor.run(FORWARD);
leftMotor.run(BACKWARD);
Serial.println("Forward, forward, forward.");
delay(straightDelay);
}