-
Notifications
You must be signed in to change notification settings - Fork 8
Examples Transformations
Luis Llamas edited this page Apr 25, 2019
·
10 revisions
★ = important
#include "ReactiveArduinoLib.h"
int values[] = { 0, 1, 1, 2, 1, 5, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);
auto observableArray = Reactive::FromArray<int>(values, valuesLength);
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableArray
>> Reactive::Select<int>([](int x) {return x * 2; })
>> Reactive::ToSerial<int>();
}
void loop()
{
}
#include "ReactiveArduinoLib.h"
auto observableInt = Reactive::FromProperty<int>();
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableInt
>> Reactive::Cast<int, float>()
>> Reactive::ToSerial<float>();
}
void loop()
{
delay(1000);
observableInt = 1;
delay(1000);
observableInt = 2;
delay(1000);
observableInt = 2;
delay(1000);
observableInt = 3;
}
#include "ReactiveArduinoLib.h"
int values[] = { 0, 1, 1, 2, 1, 5, 4 };
size_t valuesLength = sizeof(values) / sizeof(values[0]);
auto observableArray = Reactive::FromArray<int>(values, valuesLength);
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableArray
>> Reactive::Map<int, double>([](int x) { return 2.0 * x; })
>> Reactive::ToSerial<double>();
}
void loop()
{
}
#include "ReactiveArduinoLib.h"
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
Reactive::FromRange<int>(0, 10)
>> Reactive::Reduce<int>([](int acum, int current) { return acum + current; })
>> Reactive::ToSerial<int>();
}
void loop()
{
}
#include "ReactiveArduinoLib.h"
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
Reactive::FromRange<int>(0, 10)
>> Reactive::Limit<int>(2, 5)
>> Reactive::ToSerial<int>();
}
void loop()
{
}
#include "ReactiveArduinoLib.h"
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
Reactive::FromRange<int>(0, 10)
>> Reactive::Scale<int>(0, 10, 100, 200)
>> Reactive::ToSerial<int>();
}
void loop()
{
}
#include "ReactiveArduinoLib.h"
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
Reactive::FromRange<int>(0, 10)
>> Reactive::Scale<int>(100)
>> Reactive::ToSerial<int>();
}
void loop()
{
}
#include "ReactiveArduinoLib.h"
auto observableInt = Reactive::FromProperty<int>();
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableInt
>> Reactive::Millis<int>() // Millis() or Micros()
>> Reactive::ToSerial<unsigned long>();
}
void loop()
{
delay(1000);
observableInt = 1;
delay(1000);
observableInt = 2;
delay(1000);
observableInt = 2;
delay(1000);
observableInt = 3;
}
#include "ReactiveArduinoLib.h"
auto observableInt = Reactive::FromProperty<int>();
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableInt
>> Reactive::Frequency<int>()
>> Reactive::ToSerial<float>();
}
void loop()
{
delay(2000);
observableInt = 1;
}