A boolean that inverts its value after an expiration time.
To start the timer, the following conditions must be met:
- An expiration time must be set (during declaration or by calling
setExpiration
). - A value must be assigned (during declaration, by calling
setValue
or by using the assignment opertor =).
TimedBool b;
b
is initialized with the value false
and no expiration time.
The timer ist not startet.
TimedBool b(2000);
b
is initialized with the value false
and an expiration time of 2000 ms.
The timer ist not startet.
TimedBool b(2000, true);
b
is initialized to true
, with an expiration time of 2000 milliseconds.
The timer is started and after the expiration time has elapsed the value is changed to false
.
This can be used to assing a value and an expiration time in a single line of code:
b = TimedBool(2000, true);
Short version:
b = {2000, true};
void setExpiration(unsigned long expiration);
Set or changes the expiration time (in milliseconds).
Setting the expiration time does not start the timer.
unsigned long getExpiration();
Returns the expiration time.
void setValue(bool value);
Set the value.
Setting a value starts the timer if an expiration time has been set before.
When the expiration time is elapsed, the value is inverted.
bool getValue();
Returns the current value.
operator bool();
This allows to use a TimedBool
like a standard boolean:
if (b == true) ...
if (b == false) ...
TimedBool& operator=();
This allows a TimedBool
to be assigned a value (true
or false
) like a standard boolean.
b = true;
b = false;
Setting a value starts the timer if an expiration time has been set before.
When the expiration time is elapsed, the value is inverted.
platformio.ini
lib_deps =
https://github.com/sivar2311/TimedBool.git