Created
May 9, 2024 12:54
-
-
Save lesterlo/274d45b060e278970af4f5a59b30c075 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int INTERVAL = 10; | |
uint64_t _previous_msTimeNow=0; | |
void loop_A() | |
{ | |
uint64_t msTimeNow = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); | |
if(msTimeNow % INTERVAL == 0) | |
{ | |
doSomething(); | |
} | |
} | |
void loop_B() | |
{ | |
uint64_t msTimeNow = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); | |
if(msTimeNow - _previous_msTimeNow >= INTERVAL) | |
{ | |
_previous_msTimeNow = msTimeNow; | |
doSomething(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment