Help me fix the count issue

 if (count>0 &&  sensorState1 == LOW){ toupon();}             //turns ON light from 1st to last step
  if (count>0 &&  sensorState4 == LOW){ todownon();}      //Turns On light from last to 1st step

if i use this in above code..it works for every count in loop.. like 1 or 2 or 3 etc it just does all the thinks in the void toupon(); or todownon(); all again
soo i changed to this way

 if (count=0 &&  sensorState1 == LOW){ toupon();}
 if (count=0 &&  sensorState4 == LOW){ todownon();} 

but the problem here is ..it just not count more than 1 ...just loops 1 every time its triggered
my motive is turn on lights only when count one is triggered and after that it just do the count job and not repeat the same lights funtion as already lights are turned on. help me fix this

full code

#include <ShiftRegister74HC595.h>
// create a global shift register object
// parameters: <number of shift registers> (data pin, clock pin, latch pin)
ShiftRegister74HC595<2> sr(14, 16, 15);

#define sensorPin1 5        //ir sensor 1
#define sensorPin2 7        //ir sensor 2
#define sensorPin3 9        //ir sensor 3
#define sensorPin4 11       //ir sensor 4



int sensorState1 = 0;
int sensorState2 = 0;
int sensorState3 = 0;
int sensorState4 = 0;
int count=0;
int time1=100;

void toupon() {                  //Turn on 1st to last light   
   for(int i=0;i<16;i++) {
      sr.set(i, HIGH);
      delay(time1);
      Serial.print("turn on light");
      Serial.println(i);
   }
}



void toupoff() {                  //Turn off from 1st to last light
   for(int i=0;i<16;i++) {
      sr.set(i, LOW);
      delay(time1);
      Serial.print("turn off light ");
      Serial.println(i);
   }
}

void todownon() {                 //turn on last to first light  
   
   for(int i = 15; i>=0; i--) {
      sr.set(i, HIGH);
      delay(time1);
      Serial.print("turn on light ");
      Serial.println(i);
   }
}
 
void todownoff() {                //turn off last to first light       

   for(int i = 15; i>=0; i--) {
      sr.set(i, LOW);
      delay(time1);
      Serial.print("turn off light ");
      Serial.println(i);
   }
}

void setup()
{
  Serial.begin(9600);
  Serial.println("FUN Started");
  Serial.print(count);
  pinMode (sensorPin1,INPUT);
  pinMode (sensorPin2, INPUT);
  pinMode (sensorPin3,INPUT);
  pinMode (sensorPin4,INPUT);
  
  
 
}

void loop() {
  int timex=800;
  
  sensorState1 = digitalRead(sensorPin1);
  sensorState2 = digitalRead(sensorPin2);
  sensorState3 = digitalRead(sensorPin3);
  sensorState4 = digitalRead(sensorPin4);
  int lower = digitalRead(sensorPin1);
  int upper = digitalRead(sensorPin4);

 if (count < 0)
    {
      count = 0;
    }
if(sensorState1 == LOW || sensorState4 == LOW ){   //counts people IN
    count++; 
    Serial.println(count);
    delay(timex);
  }

  if(sensorState2 == LOW || sensorState3 == LOW ){   //counts people OUT
    count--; 
    Serial.println(count);
    delay(timex);
  }
    if(count<=0 && sensorState2 == LOW)
   
  {
    todownoff();
   
  }

if(count<=0 && sensorState3 == LOW)
   
  {
    toupoff();
   
  }

  
  if (count>0 &&  sensorState1 == LOW)
{ 
toupon();
}
  if (count>0 &&  sensorState4 == LOW)
{
 todownon();
} 

  }

count=0 should be count==0

did you mean == ?

acutally sorry fixed it.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.