There are plenty of suggestions for using millis instead of delay.
I'm struggling to introduce required delay using millis, below is what I'm trying to do, I, know time duration is not being incremented but do not know how I, write it
unsigned long currentmillis = millis();
while ((currentmillis < duration)) {
digitalWrite(8, HIGH);
// delay(20);
digitalWrite(8, LOW);
continue;
enclosing the code, pl suggest me how I, can achieve the delay with millis.
@Robin2
The fact that OP is using a while statement suggests to me that he/she is not approaching the problem from anywhere near the correct direction. It may well be that delay() is perfectly OK to use. It's hard to say, though, because the posted code doesn't use delay() at all.
While supplying links is perfectly reasonable most of the time, I don't think this is such a time.
unsigned long currentmillis = millis();
while ((currentmillis<duration)) {
digitalWrite(8, HIGH);
// delay(20);
digitalWrite(8, LOW);
continue;
}
It makes NO sense to compare now to an interval.
The continue statement will jump to the end of the block, bypassing any code between it and the end of the block. Using that statement as the last statement in the block is a sign of cluelessness.
Once the body of the while statement starts executing, it will NEVER end, because the condition, if true to start with, will remain true forever, since neither variable's value is changed in the body of the while statement.
I, want to avoid delay when fault occurs switching on LED for 20 msecs,as I, will be missing counting the pulses.
That is nonsense, since the pulses are counted in ISRs triggered by interrupts which continue to happen while delay() is doing its head-in-the-sand bit.