Skip to content

Examples Filters

Luis Llamas edited this page Aug 24, 2019 · 6 revisions

OnRising/OnFalling

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4, 2, 6, 2, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	FromArray<int>(values, valuesLength)
	>> OnFalling<int>()  //OnRising or OnFalling
	>> ToSerial<int>();
}

void loop()
{
}

Median3/Median5

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4, 2, 6, 2, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	FromArray<int>(values, valuesLength)
	>> Median3<int>() // Median3 or Median5
	>> ToSerial<int>();
}

void loop()
{
}

MovingAverage/MovingRMS

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4, 2, 6, 2, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	FromArray<int>(values, valuesLength)
	>> MovingAverage<int>(4)  //MovingAverage or MovingRMS
	>> ToSerial<int>();
}

void loop()
{
}

LowPass/HighPass

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4, 2, 6, 2, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	FromArray<int>(values, valuesLength)
	>> Cast<int, float>()
	>> LowPass<float>(0.4)  //LowPass or HighPass
	>> ToSerial<float>();
}

void loop()
{
}

PassBand/StopBand

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4, 2, 6, 2, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	FromArray<int>(values, valuesLength)
	>> Cast<int, float>()
	>> PassBand<float>(0.35, 0.65) //PassBand or StopBand
	>> ToSerial<float>();
}

void loop()
{
}

Debounce (millis or micros)

#include "ReactiveArduinoLib.h"

auto observableInt = FromProperty<int>();

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	observableInt
		>> DebounceMillis<int>(25)  //DebounceMillis or DebounceMicros
		>> ToSerial<int>();
}

void loop()
{
	delay(2000);
	observableInt = 1;
	delay(10);
	observableInt = 2;  // Debounce ignore this
	delay(5);
	observableInt = 2;  // Debounce ignore this
	delay(100);
	observableInt = 3;
}

IsGreater/IsLower/IsEquals/IsNotEquals...

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4, 2, 6, 2, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	FromArray<int>(values, valuesLength)
	>> IsGreater(3)
	>> ToSerial<int>();
}

void loop()
{
}

IsZero/IsNotZero

#include "ReactiveArduinoLib.h"

int values[] = { 0, 1, 1, 2, 1, 5, 4, 2, 6, 2, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);

void setup()
{
	Serial.begin(9600);
	while (!Serial) delay(1);

	FromArray<int>(values, valuesLength)
	>> IsZero<int>()
	>> ToSerial<int>();
}

void loop()
{
}
Clone this wiki locally