Blink Without Delay

For my project I use 2 sensors and 2 led strips. I want to let both led strips light up without interrupting each other while reading the different values from the inputs. But Arduino still pauses when one lights up, the other one needs to wait for the time to pass, either one misses reading the value when one is processing the output. I took a reference from this tutorial https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
Can somebody tell me what's the problem?
Thanks.

#include <Adafruit_NeoPixel.h>
#define PIN 6
int ledFadeTime = 7;
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(60, 9, NEO_GRB + NEO_KHZ800);//led pin
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(60, 7, NEO_GRB + NEO_KHZ800);//led pin
const int sensorPin3 = A2;//motion sensor
const int sensorPin4 = A3; //flash sensor
 
unsigned long strip3OnTime;
unsigned long strip4OnTime;
bool strip3On;
bool strip4On;
 
void setup() {

  Serial.begin(9600);
  strip3.begin();
  strip3.show();
  strip4.begin();
  strip4.show();
  
  strip3On = false;
  strip4On = false; 
}
 
void loop(){
 int Val3 = analogRead (sensorPin3); // sensor val
 int Val4 = analogRead (sensorPin4); 
 
 Serial.print(Val3);
 Serial.print(" ");
 Serial.println(Val4);

 
  if (Val3>70) {  
    rgbFadeInAndOut3(0, 0, 255, ledFadeTime);   
    //analogWrite(strip3, HIGH);
    strip3On = true;
    strip3OnTime = millis();
  }
  if (Val4>70) {    
    rgbFadeInAndOut4(0, 0, 255, ledFadeTime); 
    //analogWrite(strip4, HIGH);
    strip4On = true;
    strip4OnTime = millis();
  }
 
  if(strip3On) 
    if(millis() - strip3OnTime > 1000) {
      rgbFadeInAndOut3(0, 0, 0, 500); 
      strip3On = false;
    }   
  if(strip4On) 
    if(millis() - strip4OnTime > 1000) {
      rgbFadeInAndOut4(0, 0, 0, 500); 
      strip4On = false;
    }
}

void rgbFadeInAndOut3(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait) {
  for(uint8_t b = 0; b <255; b++) {
     for(uint8_t i=0; i < strip3.numPixels(); i++) {
        strip3.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
     }

     strip3.show();
     delay(wait);
  };

  for(uint8_t b=255; b > 0; b--) {
     for(uint8_t i = 0; i < strip4.numPixels(); i++) {
        strip3.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
     }
     strip3.show();
     delay(wait);
  };
};

void rgbFadeInAndOut4(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait) {
  for(uint8_t b = 0; b <255; b++) {
     for(uint8_t i=0; i < strip4.numPixels(); i++) {
        strip4.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
     }

     strip4.show();
     delay(wait);
  };

  for(uint8_t b=255; b > 0; b--) {
     for(uint8_t i = 0; i < strip4.numPixels(); i++) {
        strip4.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
     }
     strip4.show();
     delay(wait);
  };
};
delay(wait);

it's supposed to be "blink without delay"

@BulldogLowell, I just removed delay(wait);, but it is still the same except the light animation is shortened to 1 second, it's supposed to be 6 seconds.

The delay() had a purpose... Of course it made it delay but it also blocked. You want to remove the delay() to not block everything but of course you have to implement the delay in another fashion :slight_smile:

So should I keep it or not? Or is there a way to tweak? Please let me know, thanks so much!

Don't keep it, because it's blocking. But you can't simply delete it and expect it to behave the same. You have to replace it with a "Blink without delay"-equivalent.

It is a shame that Adafruit publishes those blocky functions in nearly every NeoPixel example.

Anyone wanting to race to the finish line on a project, who wishes to use those functions, invariably ends up dealing with their respective blockiness, or abandoning the idea of incorporating them into a project...