sivar2311 / TimedBool

Arduino library for a boolean that inverts its value after an expiration time.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TimedBool

A boolean that inverts its value after an expiration time.

To start the timer, the following conditions must be met:

Declaration

Default declaration

TimedBool b;

b is initialized with the value false and no expiration time.

The timer ist not startet.

Declaration with expiration time

TimedBool b(2000);

b is initialized with the value false and an expiration time of 2000 ms.

The timer ist not startet.

Declaration with expiration time and value

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};

Methods

setExpiration

void setExpiration(unsigned long expiration);

Set or changes the expiration time (in milliseconds).

Setting the expiration time does not start the timer.

getExpiration

unsigned long getExpiration();

Returns the expiration time.

setValue

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.

getValue

bool getValue();

Returns the current value.

Operators

Conversion operator bool

operator bool();

This allows to use a TimedBool like a standard boolean:

  if (b == true) ...
  if (b == false) ...

Assignment operator

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.

Installation (PlatformIO)

platformio.ini

lib_deps = 
  https://github.com/sivar2311/TimedBool.git

About

Arduino library for a boolean that inverts its value after an expiration time.


Languages

Language:C++ 100.0%