Function millis()

Hi everyone!!,

I am using the function millis() to lit an led strips....each interval( a time that I set) It get into the an if and check a variable....and what I want to do and It doesnt work is turn off the led strips each one second...using millis() function too...but It doesnt work, It seems that It doenst get into the sencond if....any idea why It's not working as I was expecting???, and I'm using as well function delay() I dont know if delay() is affected by using millis()....I guess it should work properly but I'm not sure...here is my code....and I'm using differents variable to using function millis() in differents if...here is my code:

#include <TimerOne.h>
#include "Wire.h"

int BH1750_Device = 0x23;
int LedPin1 = 10;
int LedPin2 = 9;
long previousMillis = 0;
long previousMillis2 = 0;
long interval = 500;
long interval2 = 1000;



int T1 = 0;
int intervalLux = 10;
int minusintervalLux = -10;
int previousLux = 0;
int Timer1count = 0;
int previousT1 = 0;
int change = 0;
int save = 0;




void setup(){
  
  Timer1.initialize(100);
  Wire.begin();
  Serial.begin(9600);
  pinMode(LedPin1,OUTPUT);
  pinMode(LedPin2,OUTPUT);
  configure_BH1750();
  //set timer1 interrupt at 1Hz

}


void loop(){
  unsigned long currentMillis = millis();
  unsigned long currentMillis2 = millis();
  int  currentLux = BH1750_Read();
  Serial.print("measurement in lux:");
  Serial.print(currentLux);
  Timer1.pwm(LedPin1,T1);
  Timer1.pwm(LedPin2,T1);


 if(currentMillis - previousMillis > interval) {

        previousMillis = currentMillis; 
    if( T1 > 200){
               T1 = 0;
               previousT1 = 0;
    }
    
    if( currentLux - previousLux >= intervalLux){
           previousLux =  currentLux;
             if(0 <= T1 < 20){
               change = 2;
             }
             else if(20 <= T1 < 50){
               change = 5;
              }
             else{
                change = 10;
              }               
                 
             T1 = previousT1 + change;
             previousT1 = T1;
             }
 
     if( currentLux - previousLux <= minusintervalLux){
           previousLux =  currentLux;
           if(0 <= T1 < 20){
               change = 2;
             }
             else if(20 <= T1 < 50){
               change = 5;
              }
             else{
                change = 10;
              } 
          
           T1 = previousT1 + change;
           previousT1 = T1;
           
      }

  }
  
   if(currentMillis2 - previousMillis2 > interval2){
             
            previousMillis = currentMillis; 
            save = T1;
            T1 = 0;
            delay(200);
            T1 = save;
   }         
            
}
  int BH1750_Read()
{
  unsigned int i=0;
  Wire.beginTransmission(BH1750_Device);
  Wire.requestFrom(BH1750_Device, 2);
  while(Wire.available())
  {
    i <<=8;
    i|= Wire.read();
  }
  Wire.endTransmission();
  return i/1.2; // Convert to Lux
  
}

void configure_BH1750()
{
  Wire.beginTransmission(BH1750_Device);
  Wire.write(0x13);        //set resolution to 4 lux  countinouosly L-resolution mode,each 16ms make a measure
  Wire.endTransmission();
}
             if(0 <= T1 < 20){

That is NOT how to check that a value is in a range.

             if(T1 >= 0 && T1 < 20)
             {

That is how to check that a value is in a range.

Not sure I understand what you need.

if(currentMillis2 - previousMillis2 > interval2){

previousMillis = currentMillis;
Is this really what you wanted?

Whenever you deal with millis() always use "unsigned long" type.

.

Thank you Pauls I'll change that too...

LarryD, yes what I want to do is that, I have used long unsigned type...It is working for the first if( if you look at up, you'll see other if with the same structure that you have quoted but with other variables..I want that my program get into the first if each interval and It gets into the one you have quoted each interval2.....

Here yes but:
unsigned long currentMillis = millis();
unsigned long currentMillis2 = millis();

No unsigned long here!
long previousMillis = 0;
long previousMillis2 = 0;
long interval = 500;
long interval2 = 1000;

So you didn't want?
if(currentMillis2 - previousMillis2 > interval2){
previousMillis2 = currentMillis2;

ok that's true.,thanks!!!, nut do you think It can be the reason my program, the one I posted is getting just in the first if??

hey I realized, that's true I was updating on previousMillis = currentMillis; not on previousMillis2 = currentMillis2; but It's a program that I have done now to ask this, the real had previousMillis2 = currentMillis2; so changing the variable to long usigned and updating the matter information to the second if..do you think It shoudl ge into the second if??

Thanks!!