so in my code (below) I have a pretty simple if statement that appears to be simply ignored, and I have no idea why.
if(stopper == true && clive < 5){ //EIGHT
presenceState = cinput;
stopper = false;
bolttimer = rtime;} else if(clive >= 5){ <--
paddlestarter = 1; <-- These lines just get ignored. When clive >=5, the motor
doesn't turn off
digitalWrite(paddlemotorControl, LOW); <--
}
Here's the rest of the code.
[left]#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Servo.h>
Servo servo;
unsigned long rtime;
int paddlemotorControl = 8;
int turnmotorControl = 9;
int endmotorControl = 10;
unsigned long timer = 0;
unsigned long bolttimer = 0;
const byte buttonPin = 11;
byte buttonState = LOW;
byte lastButtonState = LOW;
boolean servoFlag = false;
const int buttonaddPin = 12;
int buttonaddState = 0;
int totalcounter = 0;
int tcounter = 0; //total bolts
int cinput = 0;
int coutput = 0;
int cstorage = 0;
int clive = 0;
int prevcinput = 0;
int cbatcher = 0;
int dclive = 0;
int dtcounter = 0;
int currentState = 0; //For the final light gate
int previousState = 0;
int currentState2 = 0; //For the initial light gate
int previousState2 = 0;
int sensorPin = A0; //For the final light gate
int sensorValue = 0;
int sensorPin2 = A1; //For the initial light gate
int sensorValue2 = 0;
int load = 0;
int starter = 0;
int paddlestarter = 0;
int turnstarter = 0;
int var = 0;
int batch = 0;
boolean stopper = false;
int presenceState = 0;
int c1 = 0;
int c2 = 0;
int cs = 0;
int ps = 0;
int dps1 = 0;
int dps2 = 0;
LiquidCrystal_I2C lcd(0x27,20,4);
void setup() {
servo.attach(2);
pinMode(buttonPin, INPUT);
pinMode(buttonaddPin,INPUT);
pinMode(paddlemotorControl, OUTPUT);
pinMode(turnmotorControl, OUTPUT);
pinMode(endmotorControl, OUTPUT);
Serial.begin(9600);
servo.write(0);
lcd.init();Â Â Â Â Â Â Â Â Â Â Â // initialize the lcd
lcd.init();
lcd.backlight();
}
void loop(){
rtime = millis();Â
tcounter = totalcounter - coutput;
clive = cinput - coutput;
Serial.println("c");
Serial.println(paddlestarter);
Serial.println();
Serial.println("t");
Serial.println();
Serial.println();
Serial.println("s");
Serial.println();
Serial.println();
if (stopper == false){
Serial.println("Connected!");
}else{
Serial.println("Failed!");}
if(starter == 0){Â //ONE
 digitalWrite(endmotorControl, HIGH);
}
if(paddlestarter == 0){
 digitalWrite(paddlemotorControl, HIGH);
}
if(turnstarter == 0){
 digitalWrite(turnmotorControl, HIGH);
}
Â
lcd.setCursor(0,0); // TWO
lcd.print("RGS Cash Guys");
lcd.setCursor(0,1);
lcd.print("Bolt Distribution");
 lcd.setCursor(0,2);
lcd.print("Qashqai =");
lcd.setCursor(4,3);
lcd.print(" bolts are live");
if(clive < 10){
 lcd.setCursor(0,3);
lcd.print(clive);
 lcd.setCursor(1,3);
lcd.print("Â ");
}
if(clive >= 10){
 if(clive <= 100){
    lcd.setCursor(0,3);
lcd.print(clive);
 lcd.setCursor(2,3);
lcd.print("Â ");Â Â }}
 Â
if(clive >= 100){
   lcd.setCursor(0,3);
lcd.print(clive);
 lcd.setCursor(3,3);
lcd.print("Â ");}
Â
if(tcounter < 10){
   lcd.setCursor(10,2);
lcd.print(tcounter);
 lcd.setCursor(11,2);
lcd.print("Â ");}
if(tcounter >= 10){
 if(tcounter <= 100){
    lcd.setCursor(10,2);
lcd.print(tcounter);
 lcd.setCursor(12,2);
lcd.print("Â ");Â Â }}
 Â
if(tcounter >= 100){
   lcd.setCursor(10,2);
lcd.print(tcounter);
 lcd.setCursor(13,2);
lcd.print("Â ");Â }
Â
Â
buttonState = digitalRead(buttonPin);
buttonaddState = digitalRead(buttonaddPin);
if(buttonaddState == HIGH){//to add bolts, count 10 and add, then press button to sync with counter system
 cs = 1; }else{
 cs = 0;
 ps = 0;}
if(cs != ps) {
 if(cs == 1){
  totalcounter = totalcounter + 10;Â
  ps = 1;
 }}
 Â
sensorValue2 = analogRead(sensorPin2); // read input value of 1st light gate
if (sensorValue2 <= 10) {
currentState2 = 1;} else {
currentState2 = 0;}
if(currentState2 != previousState2){
 if(currentState2 == 1){
 cinput = cinput + 1;}}
Â
previousState2 = currentState2;
sensorValue = analogRead(sensorPin); //read sensor value of 2nd light gate
if (sensorValue <= 10) {
 currentState = 1;} else {
 currentState = 0;}
Â
if(currentState != previousState){
 if(currentState == 1){
coutput = coutput + 1;}}
previousState = currentState;
if(cinput != prevcinput){Â // THREE
 paddlestarter = 1;
 digitalWrite(paddlemotorControl, LOW);
 stopper = true;
 }
Â
prevcinput = cinput;
Â
Â
if(clive >= 8){ //FOUR
 turnstarter = 1;
  digitalWrite(turnmotorControl, LOW);}Â
 Â
 Â
 Â
 Â
if(coutput - 4 == cbatcher){Â ///FIVE
 digitalWrite(endmotorControl, LOW);
Â
 batch = batch + 1;
 cbatcher = coutput;
 load = 1;
 starter = 1;}
if(load == 1){Â //SIX
 if (servoFlag == false && lastButtonState != buttonState)
{
 lastButtonState = buttonState;
 if (buttonState == HIGH)
 {
  servo.write(60);
  Serial.println("servo at 60");
  timer = rtime;
  servoFlag = true;
 }
}}
if (servoFlag == true && rtime - timer >= 7500)
{
 servo.write(0);
 Serial.println("servo at 0");
 load = 0;
 starter = 0;
 servoFlag = false;
}
if(batch >= 2){Â //SEVEN
  turnstarter = 0;
  batch = 0;}
 Â
if((stopper == true) && (clive < 5)){Â //EIGHT
presenceState = cinput;
stopper = false;
bolttimer = rtime;} else if(clive >= 5){
paddlestarter = 1;
digitalWrite(paddlemotorControl, LOW);
}
if(presenceState == cinput && bolttimer <= rtime - 5000){
paddlestarter = 0;
stopper = false;
bolttimer = 0;
presenceState = 0;
 } else { if(bolttimer <= rtime - 5000){
  bolttimer = 0;
 }}
}[/left]
p.s. soz about this, I hate to post 300 lines but I have no clue why this won't work.