Using long datatype in if loop whats it use?

if ((long)(LCDtimer + 100) < millis())

Please read forum guide in sticky post.

Someone thought that they needed to cast LCDtimer + 100 to a long type to compare to another long type.

They did not need to do that. It means the same as

if (LCDtimer + 100 < millis())

Besides the fact that the proper unnecessary cast would have been to unsigned long, the return type of miils().

a7

Bad code. Will fail on millis() rollover. Should use

  if(millis() - LCDtimer  > 100) {

It's 'true' if it has been more than 100 milliseconds since LCDtimer was set to millis().

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.