For loops and millis timing

Hey I was wondering how one would go about combining for loops and millis.

I have one of two lights that blink at random every 3.5 sec for 1.5 sec. Instead of blink each light once however, I would like to blink each one say 3 times instead.

const int LEDLeftPin = 6;
const int LEDRightPin = 5;

const int ButtonLeftPin = 13;
const int ButtonRightPin = 12;
  
int rand_val;

int ButtonLeftState, ButtonRightState;

boolean ButtonPressed = false;
boolean LEDNotRegistered = false;
boolean TestComplete = false;
boolean NotRun = false;

long previousMillis = 0;
long interval = 3500;
int VibDelay = 2000;

int loopNo = 0;
const int TotalLoops = 14;

float CorrectAnswer = 0;
float WrongAnswer = 0;
float VibMissed = 0;

float PerCorrect = 0;
float PerWrong = 0;
float PerMissed = 0;

void setup(){
  Serial.begin(9600);
  pinMode(LEDLeftPin,OUTPUT);
  pinMode(LEDRightPin,OUTPUT);

  pinMode(ButtonLeftPin,INPUT);
  pinMode(ButtonRightPin,INPUT);

  randomSeed(analogRead(0));
}

void loop(){
  unsigned long currentMillis = millis();
  int test = interval + (interval * loopNo);
  
  
  if((currentMillis - previousMillis <= interval) && (loopNo <= TotalLoops) &&(!NotRun)) {
    previousMillis = currentMillis;
    NotRun = true;
    rand_val = random(0,2);
    loopNo++;
    
    Serial.println(rand_val);
    Serial.println(loopNo);
    
    //Activate lights
   
    if(rand_val == 0) {
         digitalWrite(LEDLeftPin,HIGH);
         digitalWrite(LEDRightPin,LOW);
    }
    
    else if(rand_val == 1) {
          digitalWrite(LEDRightPin,HIGH);
          digitalWrite(LEDLeftPin,LOW);
      }      
  }
 
 //Delaying light
 if((currentMillis - previousMillis >= interval -VibDelay) && (currentMillis - previousMillis <= interval)){
 digitalWrite(LEDLeftPin,LOW);
 digitalWrite(LEDRightPin,LOW);
 }
}

Just keep a counter. Increment it each time you toggle the state of the LED, and check if it’s >= 3 where you check the time, and if so, don’t turn the LED on.

Thanks but how would I go about setting the amount of time the LED needs to be on and off. It would have been easy using delays but i need a button press to be registered simultaneously so that’s not possible.

This is basically what im looking at doing, but with millis as opposed to delays.

if((currentMillis - previousMillis <= interval) && (loopNo <= TotalLoops) &&(!NotRun)) {
    previousMillis = currentMillis;
    NotRun = true;
    rand_val = random(0,2);
    loopNo++;
    
    Serial.println(rand_val);
    Serial.println(loopNo);
    
    //Activate lights
   
    if(rand_val == 0) {
for (loopNo = 0; loopNo < TotalLoops; loopNo++){
         digitalWrite(LEDLeftPin,HIGH);
delay(500);
         digitalWrite(LEDRightPin,LOW);
delay(500);
}
    }
    
    else if(rand_val == 1) {
for (loopNo= 0; loopNo< TotalLoops; loopNo++){
          digitalWrite(LEDRightPin,HIGH);
delay(500);
          digitalWrite(LEDLeftPin,LOW);
delay(500);
}
      }      
  }

And the new forums strike again..

If you're using millis() and checking it against an interval, you're already doing it. This topic may help you.

Thanks for the help, I will look into this.