#include /* This Rugged Motor Shield application demonstrates basic DC motor control. * * Assumptions: * * - two DC motors connected to the 2 motor outputs * - 8V-30V supply connected to Vin (optional, else Arduino Vin is used) * - Vin jumper is cut (J21) (only required if Vin>15V) * * The behavior is as follows: * * - Motor 1 spins forward for 1 second * - Motor 1 stops for 1 second * - Motor 1 spins in reverse for 1 second * - Motor 1 stops for 1 second * - Motor 2 spins forward for 1 second * - Motor 2 stops for 1 second * - Motor 2 spins in reverse for 1 second * - Motor 2 stops for 1 second * * The above motions repeat in an endless loop * * This software is licensed under the GNU General Public License (GPL) Version * 3 or later. This license is described at * http://www.gnu.org/licenses/gpl.html * * Application Version 1.0 -- October 2010 Rugged Circuits LLC * http://www.ruggedcircuits.com */ // 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 off for now pinMode(EN1_PIN, OUTPUT); digitalWrite(EN1_PIN, LOW); pinMode(EN2_PIN, OUTPUT); digitalWrite(EN2_PIN, LOW); pinMode(DIR1_PIN, OUTPUT); digitalWrite(DIR1_PIN, LOW); pinMode(DIR2_PIN, OUTPUT); digitalWrite(DIR2_PIN, LOW); // Both motors off for now analogWrite(EN1_PIN, 0); analogWrite(EN2_PIN, 0); } void loop() { digitalWrite(DIR1_PIN, LOW); // Set Motor 1 forward direction analogWrite(EN1_PIN, 255); // Motor 1 on in forward direction delay(1000); analogWrite(EN1_PIN, 0); // Motor 1 off delay(1000); digitalWrite(DIR1_PIN, HIGH); // Set Motor 1 reverse direction analogWrite(EN1_PIN, 255); // Motor 1 on in reverse direction delay(1000); analogWrite(EN1_PIN, 0); // Motor 1 off delay(1000); digitalWrite(DIR2_PIN, LOW); // Set Motor 2 forward direction analogWrite(EN2_PIN, 255); // Motor 2 on in forward direction delay(1000); analogWrite(EN2_PIN, 0); // Motor 2 off delay(1000); digitalWrite(DIR2_PIN, HIGH); // Set Motor 2 reverse direction analogWrite(EN2_PIN, 255); // Motor 2 on in reverse direction delay(1000); analogWrite(EN2_PIN, 0); // Motor 2 off delay(1000); }