Skip to content

Instantly share code, notes, and snippets.

@bradllj bradllj/ArduinoSimpleRobot
Last active Feb 28, 2016

Embed
What would you like to do?
// 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
You can’t perform that action at this time.