Shift register with millis possible?

is it possible to add millis funtion for shift register leds...i making a two way ir sensor automatic lights ..as if i use delay then the lights goes on one by one as per delay but it just stops the whole sketch. and at the delay time even though the 2nd senor is triggerds..it does nothing.
soo thought millius could work..but not sure how can i use it in shift register output.
help me fix this or suggest me something better.

What you want to do will be be possible but your sketch will need to be restructured. Start by posting the code that you tried using delay() and please use code tags when you do

See How to get the best out of this forum

1 Like

before i start i need some help in merging few funtions. i made 3 projects and trying to merge them into one.
let me explain you. i made a people counter with four ir sensors and i want to add to my stair case to turn on and off lights as per the count. and thats all made thier is no issue in that.
if count is >0 then turn on all lights (without delays)
if count is =0 then turn off all lights
till this it works but
the probelm i have now is...
i dont just want to just turn on or off all lights
instead i want to turn on light one by one and also count people at the same time.
as using delays just stops the whole sketch. here is my roung 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=1000;

void toupon() {                  //Turn on 1st to last light   
   for(int i=0;i<16;i++) {
      sr.set(i, HIGH);
      delay(time1);
      Serial.print("turn off 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 off 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("Projected 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 ){       //count people IN
    count++; 
    Serial.println(count);
    delay(timex);
  }

  if(sensorState2 == LOW || sensorState3 == LOW ){             //count 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();
  } 

}

how to delete this post as i posted the updated code and details

Why did you start a new topic for the same subject ?
If I remember correctly this is not the first time that you have done this

1 Like

no actually i thought of deleteing this and make a new topic with some updated informations and code. so i created but later found i dont have access to delete this post..sorry im new to the forum and will not do that again

Topic closed