Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TimeOut.h by Heiko Indenbirken
- #ifndef _TIMEOUT_h
- #define _TIMEOUT_h
- #include "arduino.h"
- class TimeOut
- {
- unsigned ms;
- unsigned long overflow;
- public:
- TimeOut (unsigned ms);
- inline operator bool () const { return millis() >= overflow; };
- void reset ();
- void reset (unsigned ms);
- bool hasOverflow ();
- private:
- // No copy possible.
- TimeOut (const TimeOut &c);
- };
- #endif
- //
- // TimeOut class by Heiko Indenbirken
- //
- #include "TimeOut.h"
- TimeOut::TimeOut (unsigned _ms)
- : ms (_ms), overflow (millis()+ms)
- {
- }
- bool TimeOut::hasOverflow ()
- {
- if (*this)
- {
- reset ();
- return true;
- }
- return false;
- }
- void TimeOut::reset ()
- {
- overflow = millis () + ms;
- }
- void TimeOut::reset (unsigned _ms)
- {
- ms = _ms;
- overflow = millis () + ms;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement