UKHeliBob:
My suspicion is that the calculation is being done using integers but try thisvoid setup()
{
Serial.begin(115200);
byte start = 253;
byte mil = 253;
byte period = 3;
mil++; // 254
mil++; // 255
mil++; // 0
mil++; // 1
mil++; // 2
Serial.println(mil); // prints 2
Serial.println(mil - start); // prints -251
if ((byte)(mil - start) >= period)
{
Serial.println("Time passed");
}
}
void loop()
{
}
Works..
But if a cast is needed anyway,
A) Can I assume that for checking time elapsed with millis I should always cast the subtraction?
B) Doesn't it imply that in the "Using millis() for timing. A beginners guide" (thank you for this excellent one) a casting is missing in the examples and otherwise it actually won't handle correctly the millis overflow?