#include "timer.h" Timer::Timer(unsigned long duration, bool autoRestart) { this->autoRestart = autoRestart; this->duration = duration; this->endTime = duration; } void Timer::start() { this->running = true; } bool Timer::update(unsigned long delta) { if (!running) { return false; } bool timedOut = false; this->currentTime += delta; if (currentTime > this->endTime) { timedOut = true; } if (timedOut && this->autoRestart) { this->endTime += this->duration; } if (timedOut && !this->autoRestart) { running = false; } return timedOut; } bool Timer::isRunning() { return this->running; }