Go Down

Topic: trouble with timed delays (Read 376 times) previous topic - next topic


That's a little awkward way of doing it, and could be an issue down the road if you are doing things that might make the loop() skip a millis tick. The same thing can be accomplished with a single if statement for checking the time:

Code: [Select]
const unsigned long pause = 350;
const int numPositions = 4;
const byte positions[numPositions] = { 45, 90, 135, 90 };
byte positionIndex = 0;


if (difference >= pause)
  previousMillis = currentMillis;
  if (positionIndex >= numPositions)
    positionIndex = 0;

That would give you more scalability and would run even with small delays in the rest of the program.

Go Up