PaulS:
You never actually do anything with dir or motors...If the potentiometer values represent limits, names like MIN_something and MAX_something make more sense than two MAX_somethings.
Yes I was just testing to make sure I got the logic correct before connecting to the motor. Here it is with the motor code. Thanks for the tip on the MIN/MAX..
#define POT_PIN A8
#define MAX_LEFT 750
#define MIN_RIGHT 300
//Motor A
int dir1PinA = 32;
int dir2PinA = 34;
int speedPinA = 36;
int motor_speed = 250;
int dir = 0; // 0 = Left, 1 = Right
void setup() {
Serial.begin(9600);
}
void loop() {
int headRot = analogRead(POT_PIN);
// Serial.println(headRot); // read-print pot
analogWrite (speedPinA, motor_speed); //Turn motor on
if (headRot < MAX_LEFT)
{
if (headRot > MIN_RIGHT)
{
// Serial.println("Center");
} else {
// Serial.println("Min Right");
dir = 0;
}
} else {
// Serial.println("Max Left");
dir = 1;
}
flipMotorDirection(dir);
}
void flipMotorDirection(int dir)
{
if (0 == dir)
{
digitalWrite (dir1PinA , LOW);
digitalWrite (dir2PinA, HIGH);
}
else
{
digitalWrite (dir1PinA, HIGH);
digitalWrite (dir2PinA, LOW);
}
}