Hi
My first post here - so please be gentle with this noob:) After 6 months of gentle tinkering and lurking I have to admit I need to ask someone!
I am trying to get rid of delay() from within a 'for' loop, for all the good reasons discussed elsewhere.
I am running 8 LEDS with a 595 shift register (and need to read 8 potentiometers at the same time) and have the following 'for' loop within the sketch taken from the ShiftOut tutorial (which runs fine):
void loop() {
for (int thisLed = 0; thisLed < 8; thisLed++) {
registerWrite(thisLed, HIGH);
delay(250);
if (thisLed > 0) {
registerWrite(thisLed - 1, LOW);
}
else {
registerWrite(8, LOW);
}
delay(250);
}
}
I have managed to get rid of the first delay() by doing this:
void loop() {
unsigned long currentMillis = millis();
previousMillis = currentMillis;
for (int thisLed = 0; thisLed < 8; thisLed++) {
registerWrite(thisLed, HIGH);
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
if (thisLed > 0) {
registerWrite(thisLed - 1, LOW);
}
else {
registerWrite(8, LOW);
}
}
delay(250);
}
}
which works fine - having tried numerous arrangements which did not, but I cannot see a way to get rid of the second delay(). Is it possible to get rid of them both this way? Is there a way to use
if(currentMillis - previousMillis > interval)
to make the board do a 'nothing' after 250ms have passed and it will then re-iterate around the loop? Will it take another nested loop?
Thanks very much for your help.
daniel
(clinician, not coder - previous experience a few lines on a DOS .bat file to run DOOM on a work PC!)