Created
August 14, 2017 17:06
-
-
Save zallesov/5f6568a2015e5260aec78c4a19b29316 to your computer and use it in GitHub Desktop.
This file contains 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
#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