Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** Made by Biduleohm
- ** 2016/05
- */
- typedef uint32_t ulong;
- class Timer
- {
- public:
- ulong time;
- Timer();
- void reset();
- void reset(ulong _duration);
- void update();
- bool hasEnded();
- bool hasEnded(ulong _duration);
- private:
- ulong start;
- ulong duration;
- };
- Timer::Timer()
- {
- this->reset();
- }
- void Timer::reset()
- {
- this->start = millis();
- this->time = 0;
- this->duration = 0;
- }
- void Timer::reset(ulong _duration)
- {
- this->start = millis();
- this->time = 0;
- this->duration = _duration;
- }
- void Timer::update()
- {
- ulong current = millis();
- if (current < this->start) { // takes care of the overflow after ~50 days
- this->start = current;
- }
- this->time = current - this->start;
- }
- bool Timer::hasEnded()
- {
- return (this->time >= this->duration);
- }
- bool Timer::hasEnded(ulong _duration)
- {
- return (this->time >= _duration);
- }
Advertisement
Add Comment
Please, Sign In to add comment