If inside a while not working properly

Hi guys, I cant find what is wrong with the following code, that the if statement is not executed

const int  trigger = 6;       /
const int  shortPulse = 7;    
const int  longPulse= 8;      

int triggerState;

void setup() {
 pinMode(trigger, INPUT); 
 pinMode(longPulse, OUTPUT);
 pinMode(shortPulse, OUTPUT);        

}

void loop()
{
int bursts = 0;
triggerState  = digitalRead(trigger); 
if (triggerState == LOW) {
  while(bursts < 15){
      digitalWrite(shortPulse, HIGH); //#1
      delayMicroseconds(300);
      digitalWrite(shortPulse, LOW);
      delayMicroseconds(300);
      bursts++;

      if(bursts==7){  //  <<<<<<<<<<<<<<<<<<<<this does not work (is never exceuted)
      digitalWrite(longPulse, HIGH);
      delayMicroseconds(100);
      digitalWrite(longPulse, LOW);
      delayMicroseconds(100);
        }
    }

   }
}

that the if statement is not executed

Do you have some proof that bursts ever gets to be 7?

Do you have some proof that the while loop ever starts?

What is connected to the trigger pin? How? Do you have the required pullup or pulldown resistor, if whatever is connected is not holding the pin HIGH or LOW at all times?

When debugging problems with if and while it helps to print the values being tested. Are they what you expect ?

How is the trigger pin wired ? Is there a pullup or pulldown resistor in place or is its input floating at an unknown voltage ?

Yes the loop goes runs the while loop, and goes till the end.

Take a look at the attachment

Are you sure? Can you even see a 100uS pulse? Nevermind, I see you're using an oscilliscope
What if you put a Serial.println("longPulse"); in there?

What if you put a Serial.println("longPulse"); in there?

What would you learn from printing that string?

In where?

I can see something (see attachment) happening when I do:

if(bursts <=7){

or

if(bursts >=7){

But that's not what I want.

Please see the updated attachment.

output3.PNG

But that's not what I want.

What DO you want? It looks like you are trying to send some short pulses, then one long pulse, then short pulses again. Then, loop starts over, and sends the pulses again.

The pulses are on different pins. It isn't clear to me what that picture is trying to tell me.

bitoff_arduino:
Take a look at the attachment

That appears to be exactly what your sketch is written to do. The white line shows 300+ microsecond pulses on Pin 7. The red line shows that about mid-way through every set of 15 pulses there is a 100+ microsecond pulse on Pin 8. How is this different from what you wanted your sketch to do?

Talking in terms of the attached image:

I am trying to send 15 short (white) pulses, and then a at the end a long (red) pulse, and repeat the process. This works.

What I need now it to generate this long pulse after any desired number of short pulse, not just at the end.

Seems like OP has switched delays for long and short pulses. The short pulses are longer than the long ones and this may trick OP into thinking that the if statement is never invoked.

I am sorry, you guys are right. It does work the way I want, I just stupidly was not able to visualize it better.

thank you