Counting a loop

joshuabardwell:

if (millis() > testVar + 1000)

// do something
else if (millis() > testVar + 2000)
  // do something else




That is bad because millis() will have advanced between the if() and the else() check, and so there are cases that might "slip through" the logic. Better to do:



unsigned long now = millis();

if (now > testVar + 1000)
  // do something
else if (now > testVar + 2000)
  // do something else

I understand because my servo will be changing a value the whole time it is rotating and I might have made a mistake when I chose to write 'pos' once a card was read. Should I write the variable once it goes into position or as the card is read?