Ok here goes the long pain of explanation. If i run the line
if (LimitSWWest == HIGH)
I will get the Return
WestSafetySwitch
Turning West
Over and Over and ,, - in turn it doesnt stop the motor Completely it just flips back and forth on the screen, and Pause and starts the motor.
If i run the line changed to
else if (LimitSWWest == HIGH)
It will only run
Turning West
im not sure if the error is Starting from
else if ((Right > threshhold) || (Left > threshhold) || (LimitSWWest == LOW) && (Right > Left + difSence))
Here is the complete Code for your enjoyment
any suggestions or thoughts would be greatly appreciated
/*
Thomas Wood
PhotoCell Controlled Stepper Motor Left and Right
Feb 15,2012
*/
#include <Stepper.h>
#include <LiquidCrystal.h>
const int stepsPerRevolution = 200; // Turns of the motor
int inputPhotoLeft = A0; // photresistors pin
int inputPhotoRight = A1; // photresistors pin
int Left = 0; // Store readings from the photoresistors.
int Right = 0; // Store readings from the photoresistors.
int analogInput = A2; //Voltage - analog input
int analogInput1 = A3; //Voltage - analog input
int SafeSW1 = A4;
const int threshhold = 300; // this is here from reading the serial monitors value
//to get a ruff Idea of value to set And how dark you Want your motor to stop moving at
int difSence = 15; // differenace tolarance between sensors
// float vout = 0.0;
float vin = 0.0;
float vin1 = 0.0;
// variable to store the value
int value = 0;
int value1 = 0;
int LimitSWWest = 0;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);
// initialize the Lcd library on pins 2 through 7:
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
myStepper.setSpeed(150);
pinMode(13, OUTPUT);
pinMode(analogInput, INPUT);
pinMode(analogInput1, INPUT);
pinMode(SafeSW1, INPUT);
lcd.begin(16, 4);
Serial.begin(9600);
}
void loop() {
value = analogRead(analogInput);
vin = (value * 23.5) /1024;
value1 = analogRead(analogInput1);
vin1 = (value1 * 14.0) /1024;
LimitSWWest = digitalRead(SafeSW1);
lcd.clear();
lcd.setCursor(-2, 2);
lcd.print("Voltage=");
lcd.print(vin);
lcd.print("V");
lcd.setCursor(-2, 3);
lcd.print("Voltage1=");
lcd.print(vin1);
lcd.print("V");
Left = analogRead(inputPhotoLeft); // sets the photocells position left - right
Right = analogRead(inputPhotoRight);
digitalWrite(13,LOW); //led doesnt need to be on to start with
//delay(500);
if (((Left > threshhold) || (Right > threshhold)) && (Left > Right + difSence))
{
Serial.println("Turning East ");
lcd.setCursor(0, 0);
lcd.print("Turning East ");
lcd.setCursor(0, 1);
lcd.print("CounterClockWise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
else if ((Right > threshhold) || (Left > threshhold) || (LimitSWWest == LOW) && (Right > Left + difSence))
{
Serial.println("Turning West ");
lcd.setCursor(0, 0);
lcd.print("Turning West ");
lcd.setCursor(0, 1);
lcd.print("ClockWise ");
myStepper.step(stepsPerRevolution);
delay(500);
}
else if ((Left < threshhold) && (Right < threshhold))
{
lcd.print("To Dark ");
lcd.setCursor(0, 0);
lcd.print("To Dark ");
lcd.setCursor(0, 1);
lcd.print("Motor Stopped ");
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
delay(500);
}
/*
else
{
Serial.println("Nothing Happening");
lcd.setCursor(0, 0);
lcd.print("Nothing Happening");
lcd.setCursor(0, 1);
lcd.print("Nothing Happening");
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
delay(500);
}*/
else if (LimitSWWest == HIGH)
{
Serial.println("WestSafetySwitch");
lcd.setCursor(0, 0);
lcd.print("WestSafetySwitch");
lcd.setCursor(0, 1);
lcd.print("WestSafetySwitch");
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
delay(500);
}
}