-
Notifications
You must be signed in to change notification settings - Fork 8
Examples Observables
Luis Llamas edited this page Aug 26, 2019
·
13 revisions
★ = important
#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;
}
#include "ReactiveArduinoLib.h"
void setup()
{
Serial.begin(115200);
while (!Serial) delay(1);
Reactive::FromRange(1, 10, 2)
.ToSerial();
}
void loop()
{
}
#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);
}
#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()
{
}
#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);
}
#include "ReactiveArduinoLib.h"
auto interval= Reactive::IntervalMillis(1000);
void setup()
{
Serial.begin(115200);
while (!Serial) delay(1);
interval
.ToSerial();
}
void loop()
{
interval.Update();
}
#include "ReactiveArduinoLib.h"
auto timer = Reactive::TimerMillis(1000);
void setup()
{
Serial.begin(115200);
while (!Serial) delay(1);
timer
.ToSerial();
}
void loop()
{
timer.Update();
}
#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();
}
#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();
}
#include "ReactiveArduinoLib.h"
auto observableSerial = Reactive::FromSerial<int>();
void setup()
{
Serial.begin(115200);
while (!Serial) delay(1);
observableSerial
.ToSerial();
}
void loop()
{
observableSerial.Receive();
}
#include "ReactiveArduinoLib.h"
auto observableSerial = Reactive::FromSerial<float>();
void setup()
{
Serial.begin(115200);
while (!Serial) delay(1);
observableSerial
.ToSerial();
}
void loop()
{
observableSerial.Receive();
}
#include "ReactiveArduinoLib.h"
auto observableSerial = Reactive::FromSerial<String>();
void setup()
{
Serial.begin(115200);
while (!Serial) delay(1);
observableSerial
.ToSerial();
}
void loop()
{
observableSerial.Receive();
}
#include "ReactiveArduinoLib.h"
auto observableSerial = Reactive::FromSerial<char>();
void setup()
{
Serial.begin(115200);
while (!Serial) delay(1);
observableSerial
.ToSerial();
}
void loop()
{
observableSerial.Receive();
}