Skip to content

Instantly share code, notes, and snippets.

@zallesov
Created August 14, 2017 17:06
Show Gist options
  • Save zallesov/5f6568a2015e5260aec78c4a19b29316 to your computer and use it in GitHub Desktop.
Save zallesov/5f6568a2015e5260aec78c4a19b29316 to your computer and use it in GitHub Desktop.
#ifndef __TIMER_GUARD__
#define __TIMER_GUARD__
class TimeGuard {
private:
unsigned long lastUpdated = 0;
unsigned long interval;
public:
TimeGuard(unsigned long interval):interval(interval){};
void reset(){
lastUpdated = 0;
}
void setInterval(unsigned long i){
interval = i;
}
unsigned long getInterval(){
return interval;
}
bool rightTime(){
unsigned long now = millis();
if(lastUpdated == 0){
lastUpdated = now;
return false;
}
if (now - lastUpdated >= interval){
lastUpdated = now;
return true;
}
return false;
}
bool timePass(){
unsigned int now = millis();
if(lastUpdated == 0){
lastUpdated = now;
return false;
}
if (now - lastUpdated >= interval){
return true;
}
return false;
}
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment