Last active
February 28, 2016 22:19
-
-
Save bradllj/5733981b4fa7eb912ea2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Motor Controls | |
const int PWMELPin = 10; // Enable PWM Left Motor | |
const int PWMERPin = 11; // Enable PWM Right Motor | |
const int L1Pin = 6; // L1 = Left Motor Lead 1 | |
const int L2Pin = 7; // L2 = Left Motor Lead 2 | |
const int L3Pin = 4; // L3 = Right Motor Lead 1 | |
const int L4Pin = 5; // L4 = Right Motor Lead 2 | |
const int LEDPin = 13; // Telltale LED | |
const int Duration = 2000; | |
void setup() | |
{ | |
pinMode(PWMELPin, OUTPUT); | |
pinMode(PWMERPin, OUTPUT); | |
pinMode(L1Pin, OUTPUT); | |
pinMode(L2Pin, OUTPUT); | |
pinMode(L3Pin, OUTPUT); | |
pinMode(L4Pin, OUTPUT); | |
pinMode(LEDPin, OUTPUT); | |
delay(10000); | |
} | |
//Main Loop | |
void loop() | |
{ | |
MotorL(1, 1); | |
MotorR(1, 1); | |
delay(3000); | |
digitalWrite(LEDPin, HIGH); | |
MotorL(0, 1); | |
MotorR(0, 1); | |
delay(200); | |
MotorL(1, 1); | |
MotorR(0, 1); | |
delay(100); | |
} | |
// *********************************************************************** | |
// Motor Driver Routines************************************************** | |
// *********************************************************************** | |
// Function(Direction, Speed) | |
// Direction | |
// 1=Forward | |
// 0= Reverse | |
// Speed | |
// 1 = High/250 | |
// 0 = Low/20 | |
// *********************************************************************** | |
void MotorL(int Direction, int Speed) | |
{ | |
// Left Motor | |
if (Speed == 1) | |
{ | |
analogWrite(PWMELPin, 250); | |
} | |
else | |
{ | |
analogWrite(PWMELPin, 20); | |
} | |
if (Direction == 1) | |
{ | |
digitalWrite(L1Pin, HIGH); | |
digitalWrite(L2Pin, LOW); | |
} | |
else | |
{ | |
digitalWrite(L1Pin, LOW); | |
digitalWrite(L2Pin, HIGH); | |
} | |
} | |
// *********************************************************************** | |
void MotorR(int Direction, int Speed) | |
{ | |
// Right Motor | |
if (Speed == 1) | |
{ | |
analogWrite(PWMERPin, 250); | |
} | |
else | |
{ | |
analogWrite(PWMERPin, 20); | |
} | |
if (Direction == 1) | |
{ | |
digitalWrite(L3Pin, HIGH); | |
digitalWrite(L4Pin, LOW); | |
} | |
else | |
{ | |
digitalWrite(L3Pin, LOW); | |
digitalWrite(L4Pin, HIGH); | |
} | |
} | |
// *********************************************************************** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment