Thanks for the replies.
Yes, I am familiar with the blink without delay example, but unfortunately this method does not work in a for loop.
If we work with the millis() timer in void loop() then the if condition will be triggered constantly, because void loop() is constantly looping.
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
However, what happens with the same method in the for loop below is that the for loop will enter once in the if condition and then loop very very quickly through the remaining 79 times, never entering the if condition again.
byte dTime; // Speed of drive's reset in milliseconds
unsigned long previousMillis;
void resetOne(){
digitalWrite(pin+1,HIGH); // Go in reverse
for(byte s = 0;s < 80; s++){ // Loop through all tracks
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > (dTime*1000)){
previousMillis = millis();
digitalWrite(pin,HIGH);
digitalWrite(pin,LOW); }
}
currentPosition[pin] = 0; // We're reset.
digitalWrite(pin+1,LOW);
currentState[pin+1] = 0; // Ready to go forward.
}
Anybody an idea how it is possible to pause a for loop without a delay?
Thanks!