26 Metro(
unsigned long interval_millis, uint8_t autoreset = 0);
35 void interval(
unsigned long interval_millis);
67 unsigned long previous_millis;
68 unsigned long interval_millis;
71inline Metro::Metro(
unsigned long interval_millis, uint8_t autoreset)
73 this->autoreset = autoreset;
80 this->interval_millis = interval_millis;
93 if (millis() - this->previous_millis >= this->interval_millis)
101 if (this->interval_millis <= 0 || this->autoreset)
103 this->previous_millis = millis();
107 this->previous_millis += this->interval_millis;
118 if (millis() - this->previous_millis >= this->interval_millis)
128 this->previous_millis = millis();
Our own implementation of Metro class.
void reset()
Resets the timer to the current time.
bool checkWithoutReset() const
Checks if the interval has passed without resetting the timer.
Metro(unsigned long interval_millis, uint8_t autoreset=0)
Constructor to initialize the timer with a given interval and autoreset behavior.
bool check()
Checks if the interval has passed and resets the timer if true.
void interval(unsigned long interval_millis)
Sets a new interval for the timer.