Code being ignored?

:confused:
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.

It's the fault of the guy with the silly grin and the sunglasses.

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

Also please use the AutoFormat tool to indent your code for easier reading.

...R

Robin2:
It's the fault of the guy with the silly grin and the sunglasses.

I think his name might be Clive.

if( (stopper == true) && (clive < 5) )
{   //EIGHT 
  presenceState = cinput; 
  stopper = false;
  bolttimer = rtime;
}
 elif(clive >= 5)
{      <--
  paddlestarter = 1;                                    <-- These lines just get ignored.  When clive >=5, the motor 
                                                                      doesn't turn off
  digitalWrite(paddlemotorControl, LOW);     <--
  }

might work a bit better. shrug

if(presenceState = cinput

That don't look good either

AWOL:

if(presenceState = cinput

That don't look good either

should be == right? Won't make a difference for my boy clive tho, the part with this stuff worked.

eescashguys:
should be == right? Won't make a difference for my boy clive tho, the part with this stuff worked.

Ok, so don't fix it. Makes no difference to me.

Apologies master, it has been fixed. Still though whats going on

After you make changes to your sketch, repost that sketch.

Idahowalker:

if( (stopper == true) && (clive < 5) )

{   //EIGHT
 presenceState = cinput;
 stopper = false;
 bolttimer = rtime;
}
elif(clive >= 5)
{      <--
 paddlestarter = 1;                                    <-- These lines just get ignored.  When clive >=5, the motor
                                                                     doesn't turn off
 digitalWrite(paddlemotorControl, LOW);     <--
 }




might work a bit better. *shrug*

Ill give it a try sonna :wink:

Edit: Wow, it works and I love you. Why did that make a difference though?

larryd:
After you make changes to your sketch, repost that sketch.

yessir

Hi,
I think

elif(clive >= 5)

Would be getting a bit frustrated being ignored all the time.

Tom... :slight_smile:

How can you possibly stand to look at that crap (oops, I meant code)? It makes me sick.

Put EVERY { on a line BY ITSELF.
Put EVERY } on a line BY ITSELF.
Use Tools + Auto Format, and it just might become crystal clear what the problem is, or was.