The if statement below should only be executed once every 100 milliseconds, but it is executed every 200 milliseconds and is processed twice.
What's wrong?
if(millis()%100==0){...}
The code literally works when you get the time in milliseconds and it's divisible by 100.Therefore, if the next time runs less than a millisecond after one split, it will continue to be a hit, and on the contrary, if you are unlucky, you may not be able to.
Therefore, if you want to implement it as intended, you need a code that records the last time you ran it, and then runs it again after more than 100 milliseconds.Here's the reference code.
static int last=0;
int now = millis();
if((now-last)>=100){
last = now;
// TODO: Write here what you want to do every 100 milliseconds
}
There is a high possibility that this code will not work as it is, so please rewrite it accordingly.
910 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
616 Uncaught (inpromise) Error on Electron: An object could not be cloned
571 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
572 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.