I have a Arduino Duemilanove (ATmega328P with a Rugged dual 2A motor sheld. My goal is to drive a robot forward for 10 seconds. Then wait for 2 hours before returning in reverse to its starting point. Seems simple the motors start at the same time in forward. But everything I have tried to make them stop and wait 2 hours causes in out of sync motors. Basically one starts before the other.
/* Define which board you are using. Only uncomment one of the
following #define's. Or comment them all and let this file
guess the board based on the processor:
ATmega328P --> Duemilanove/Uno
ATmega324P --> Gator
ATmega1280 --> Mega (also ATmega2560)
/
//#define BOARD 0 / Arduino Duemilanove/Uno (ATmega328P) /
//#define BOARD 1 / Arduino Mega (ATmega1280) /
//#define BOARD 2 / Rugged Circuits Gator (ATmega324P) */
// In case no board is defined, guess from the processor
#ifndef BOARD
if defined(AVR_ATmega328P)
define BOARD 0
elif defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
define BOARD 1
elif defined(AVR_ATmega324P)
define BOARD 2
else
error You must define BOARD near the top of this file
endif
#endif
#if (BOARD!=0) && (BOARD!=1) && (BOARD!=2)
#error Unknown board
#endif
// Enable (PWM) outputs
#define EN1_PIN 3
#define EN2_PIN 11
// Direction outputs
#define DIR1_PIN 12
#define DIR2_PIN 13
void setup()
{
// Configure all outputs on for now
pinMode(EN1_PIN, OUTPUT); digitalWrite(EN1_PIN, HIGH);
pinMode(EN2_PIN, OUTPUT); digitalWrite(EN2_PIN, HIGH);
pinMode(DIR1_PIN, OUTPUT); digitalWrite(DIR1_PIN, HIGH);
pinMode(DIR2_PIN, OUTPUT); digitalWrite(DIR2_PIN, HIGH);
digitalWrite(DIR1_PIN, HIGH); // Set Motor 1 forward direction
analogWrite(EN1_PIN, 255); // Motor 1 on in forward direction
delay(10000);
digitalWrite(DIR1_PIN, HIGH); // Set Motor 2 forward direction
analogWrite(EN2_PIN, 255); // Motor 2 on in forward direction
delay(10000);
}