# Shift register with millis possible?

**URL:** <https://forum.arduino.cc/t/shift-register-with-millis-possible/888307>\
**Category:** Programming\
**Created:** [July 23, 2021, 2:21pm UTC](https://forum.arduino.cc/t/shift-register-with-millis-possible/888307 "2021-07-23T14:21:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![boopesh\_boo](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@boopesh\_boo](https://forum.arduino.cc/u/boopesh_boo)\
**Post date:** [July 23, 2021, 2:21pm UTC](https://forum.arduino.cc/t/shift-register-with-millis-possible/888307/1 "2021-07-23T14:21:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 23, 2021, 2:23pm UTC](https://forum.arduino.cc/t/shift-register-with-millis-possible/888307/2 "2021-07-23T14:23:54Z")

</div>

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](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code)

---

<div class="post-metadata">

**Author:** ![boopesh\_boo](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@boopesh\_boo](https://forum.arduino.cc/u/boopesh_boo)\
**Post date:** [July 23, 2021, 2:40pm UTC](https://forum.arduino.cc/t/shift-register-with-millis-possible/888307/3 "2021-07-23T14:40:24Z")

</div>

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.

```cpp
#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();
  } 

}

```

---

<div class="post-metadata">

**Author:** ![boopesh\_boo](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@boopesh\_boo](https://forum.arduino.cc/u/boopesh_boo)\
**Post date:** [July 23, 2021, 4:09pm UTC](https://forum.arduino.cc/t/shift-register-with-millis-possible/888307/4 "2021-07-23T16:09:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 23, 2021, 4:51pm UTC](https://forum.arduino.cc/t/shift-register-with-millis-possible/888307/5 "2021-07-23T16:51:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![boopesh\_boo](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@boopesh\_boo](https://forum.arduino.cc/u/boopesh_boo)\
**Post date:** [July 23, 2021, 4:55pm UTC](https://forum.arduino.cc/t/shift-register-with-millis-possible/888307/6 "2021-07-23T16:55:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 23, 2021, 5:26pm UTC](https://forum.arduino.cc/t/shift-register-with-millis-possible/888307/7 "2021-07-23T17:26:25Z")

</div>

Closed on July 23, 2021, 5:26pm UTC



---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [July 23, 2021, 5:26pm UTC](https://forum.arduino.cc/t/shift-register-with-millis-possible/888307/8 "2021-07-23T17:26:39Z")

</div>

Topic closed
