running a while loop through a ranger of parameters

wondering if there is better way to do this, working on an EFI project, ill have an ISR triggering an increment counter to keep track of the engines position. to drive my ignition, a simple if() statement will work, (e,g if{pulse = 30 - writePIN, high) but my fuel delivery must happen over a couple of pulses (e,g pulse 15-20), i was hoping to just run a while() loop during those pulses, but im not sure how to set up a rage like that, as the arduino reference explains it as a boolean (true or false). i thought maybe a do...while() loop might work, but still a bit unclear on how to structure and define this, or if im even on the right path, is there maybe another structure element i could use with better results. thx in advance for any help

To turn on a pin for pulses 15 through 20:

    if (pulse == 15)
        digitalWrite(OutputPin, HIGH);

    if (pulse == 21)
        digitalWrite(OutputPin, LOW);

could i use an if statement to define a while loop ? i need to run a specific code during those pulse, but i also have other code to run during other specific pulses, and at the speed of all this will be happening. that would take alot of if statements…

Well you could modify johnwasser’s code just a bit and do…

    if (pulse >= 15 && pulse < 21){
        runMyFunction();
    }

And do whatever you need to in the function.

kdglv: could i use an if statement to define a while loop ?

What do you mean by 'define a while loop'?

Are you asking vague questions because you don't know what you want the sketch to do or because you don't want anyone else to know what your sketch is supposed to do?

kdglv: i was hoping to just run a while() loop during those pulses

Almost certainly a WHILE loop would be a bad idea if you want a responsive program. WHILE and FOR loops block the Arduino until they complete. Just use an IF statement and allow loop() to do the iteration.

...R

I think my program would become to long if I used only if statements. Would switch cases work fast enough? I need to be able to run different block of code depending on where the counter is at.

kdglv: I think my program would become to long if I used only if statements.

If you mean "too many lines of code" then that is of no relevance - but do organise the code so it is easily understood.

If you mean that it would take too much time for loop() to repeat then the program probably needs a re-design.

I doubt if switch-case operates significantly faster than IF/ELSE - I would expect the compiler to optimise both. SWITCH/CASE is just a limited version of IF/ELSE to make code easier to understand.

...R