Skip to content

Examples Observables

Luis Llamas edited this page Aug 26, 2019 · 13 revisions

★ = important

FromProperty ★

#include "ReactiveArduinoLib.h"

auto observableInt = Reactive::Property();

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

	observableInt
	.ToSerial();
}

void loop()
{
	delay(1000);
	observableInt = 1;
	delay(1000);
	observableInt = 2;
	delay(1000);
	observableInt = 2;
	delay(1000);
	observableInt = 3;
}

Range

#include "ReactiveArduinoLib.h"

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

	Reactive::FromRange(1, 10, 2)
	.ToSerial();
}

void loop()
{
}

RangeDefer

#include "ReactiveArduinoLib.h"

auto observableRange = Reactive::FromRangeDefer(1, 5, 1);

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

	observableRange
		.ToSerial();
}

void loop()
{
	observableRange.Next();
	delay(250);
}

Array

#include "ReactiveArduinoLib.h"

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

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

	Reactive::FromArray(values, valuesLength)
	.ToSerial();
}

void loop()
{
}

ArrayDefer

#include "ReactiveArduinoLib.h"

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

auto observableArray = Reactive::FromArrayDefer(values, valuesLength);

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

	observableArray
	.ToSerial();
}

void loop()
{
	observableArray.Next();
	delay(250);
}

Interval (millis or micros)

#include "ReactiveArduinoLib.h"

auto interval= Reactive::IntervalMillis(1000);

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

	interval
	.ToSerial();
}

void loop()
{
	interval.Update();
}

Timer (millis or micros)

#include "ReactiveArduinoLib.h"

auto timer = Reactive::TimerMillis(1000);

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

	timer
	.ToSerial();
}

void loop()
{
	timer.Update();
}

Digital Input

#include "ReactiveArduinoLib.h"

auto reactiveInput = Reactive::FromDigitalInput(10, INPUT_PULLUP);

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

	reactiveInput
	.ToSerial();
}

void loop()
{
	reactiveInput.Next();
}

Analog Input

#include "ReactiveArduinoLib.h"

auto reactiveInput = Reactive::FromAnalogInput(A0, INPUT_PULLUP);

void setup()
{
	Serial.begin(115200);
	while (!Serial) delay(1);
	
	reactiveInput
	.ToSerial();
}

void loop()
{
	reactiveInput.Next();
}

FromSerial

Integer

#include "ReactiveArduinoLib.h"

auto observableSerial = Reactive::FromSerial<int>();

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

	observableSerial
	.ToSerial();
}

void loop()
{
	observableSerial.Receive();
}

Float

#include "ReactiveArduinoLib.h"

auto observableSerial = Reactive::FromSerial<float>();

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

	observableSerial
	.ToSerial();
}

void loop()
{
	observableSerial.Receive();
}

String

#include "ReactiveArduinoLib.h"

auto observableSerial = Reactive::FromSerial<String>();

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

	observableSerial
	.ToSerial();
}

void loop()
{
	observableSerial.Receive();
}

Char

#include "ReactiveArduinoLib.h"

auto observableSerial = Reactive::FromSerial<char>();

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

	observableSerial
	.ToSerial();
}

void loop()
{
	observableSerial.Receive();
}