cant get more than 2 if statements to run in my sketch

Tying to blink light twice then a short flash sort of dot-dot-dit
code will read only the first two ifs
have tried the if else
in think it is with millis issue as it reads past 300 millisecs it doesn't see third if statement to re turn on.etc.

so what is missing ?

thanks in advance for your help/.

doug

int strobePin = 13;
int ledState2 = LOW;
unsigned long previousMillis = 0;
long OnTime = 300;
long OffTime = 80;
long OnTime2 = 800; //610;
long OffTime2 = 900; // 390;
//  -----80-----300-----390-----610-------700----810----
long OffTime3 = 1700;
long OnTime3 = 1810;
void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 pinMode (strobePin, OUTPUT);

}

void loop() {
 // put your main code here, to run repeatedly:
 unsigned long currentMillis = millis();

 

if ((ledState2 == LOW) && (currentMillis - previousMillis >= OffTime))   //turn on
 {
   ledState2 = HIGH;
   previousMillis = currentMillis;
   digitalWrite(strobePin, ledState2);
   Serial.print("1   ");
   Serial.println(ledState2);
  // Serial.print(currentMillis);

 }  
   
 else if ((ledState2 == HIGH) && (currentMillis - previousMillis >= OnTime))    //turn off
   {
     ledState2= LOW;
     previousMillis = currentMillis;
     digitalWrite(strobePin, ledState2);
     Serial.print("2   ");
     Serial.println(ledState2);    
   //  Serial.print(currentMillis);
   }
 
 // ------------------------------------------------------------------
    if ((ledState2 == LOW) && (currentMillis - previousMillis >=OffTime))       //turn on
       {
         Serial.println("897979");
         ledState2 = HIGH;
         previousMillis = currentMillis;
         digitalWrite(strobePin, ledState2);
         Serial.print("3   ");
         Serial.println(ledState2);  
         
       }  
       else  if ((ledState2 == HIGH) && (currentMillis - previousMillis >= OnTime))     //turn off
         {
           ledState2= LOW;
           previousMillis = currentMillis;
           digitalWrite(strobePin, ledState2);
           Serial.print("4   ");
           Serial.println(ledState2);
         }
   
       //---------------------------------------------------------------------    
       
              if ((ledState2 == LOW) && (currentMillis - previousMillis >= OffTime3))     //turn on 1/2
             {
               ledState2 = HIGH;
               previousMillis = currentMillis;
               digitalWrite(strobePin, ledState2);
               Serial.print("5   ");
               Serial.println(ledState2);    
           
             }  
                else if ((ledState2 == HIGH) && (currentMillis - previousMillis >= OnTime3))    turn off
               {
                 ledState2= LOW;
                 previousMillis = currentMillis;
                 digitalWrite(strobePin, ledState2);
                 Serial.print("6   ");
                 Serial.println(ledState2);
               }
         
}

Use a counter to enable different pieces of code.

When one piece of code is run, increment that counter.

The new value of the counter then enables the next piece of code.

.

but would not the millis be the timer for this code?
doug

milli() returns the time since the last reset.

The counter and subsequent comparison form the timer code beging tested.

Example:

if(counter == 3 && millis() - previousMillis >= 800)
{
  // your code
  counter++;
  previousMillis = millis();
}

if(counter == 4 && millis() - previousMillis >= 400)
{
  // your code
  counter++;
  previousMillis = millis();
}

The demo Several Things at a Time illustrates the use of millis() to manage timing. It may help with understanding the technique.

…R

May be not an issue with the timming every time the sketch gets to the line to print the stobePin to LOW state it seems to return to the top of the loop and restart down.

I have inserted at the start of the third if a serial print jibberish "989897" to tell me if the loop gets that far and it never prints.

I added a counter and it comes up the same. it slides down the sketch until third if and restarts.

If you have new code, post it.

.

solved thanks !!

5546doug:
solved thanks !!

Please share your solution so others can benefit from your experience.

...R