See attached programme.
This is a very much cut down version of the whole program, but it is still bugging me.
On line 323 “if (millis() >= testing)” for some reason this If statement is not If-ing when Millis() is greater than or equal to “testing” until much later.
A few lines before I have set testing to be 4000 larger than the then current millis(), which is located inside an “if autoApos == 2”. Then autoApos is changed to 3 and the next If statement should run if autoApos == 3 && millis() >= testing.
What I am finding is that millis() can be 40000 when “testing” is 30000 (ish) before the If statement runs. I have tried many variants but I always get the same result, millis() is always 10000 to 20000 larger than the “testing” value.
No doubt someone will spot the stupid and obvious error instantly, my eyes are still fuzzy after writing the 30k programme (only 9.4k uploaded, the rest isn’t in use at this point).
I have been using Serial.print to tell me the values of different variables, out of all the different parts it only appears to be the If statement on line 323 which doesn’t add up.
If I remove the millis() if statement and just have the “if autoApos == 3” it works fine (but instantly).
The final idea is to have a random time form 3 to 10 seconds for the delay.
Another interesting thing is when the time delay If was inside the autoApos == 3 If, I had a Serial.print after the dodgy combined If autoApos && delay statement which should have ran all the time for testing (causing the MCU to run slow). This would work fine until autoApos == 3, where it would stop until the If statement was satisfied. This made no sense as the Serial.print was after the If statement (outside completely) and would otherwise run except if the If statement was 1/2 true (when autoApos == 3).
I know the If statements should me If (previous_time <= millis() - number). I’ve currently written them with a + for simplicity. This program will not run for more than 10 hours.
To_upload.ino (57.2 KB)