-
Notifications
You must be signed in to change notification settings - Fork 8
Examples Transformations
Luis Llamas edited this page Aug 24, 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 = FromArray<int>(values, valuesLength);
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableArray
>> Select<int>([](int x) {return x * 2; })
>> ToSerial<int>();
}
void loop()
{
}#include "ReactiveArduinoLib.h"
auto observableInt = FromProperty<int>();
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableInt
>> Cast<int, float>()
>> 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 = FromArray<int>(values, valuesLength);
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableArray
>> Map<int, double>([](int x) { return 2.0 * x; })
>> ToSerial<double>();
}
void loop()
{
}#include "ReactiveArduinoLib.h"
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
FromRange<int>(0, 10)
>> Reduce<int>([](int acum, int current) { return acum + current; })
>> ToSerial<int>();
}
void loop()
{
}#include "ReactiveArduinoLib.h"
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
FromRange<int>(0, 10)
>> Limit<int>(2, 5)
>> ToSerial<int>();
}
void loop()
{
}#include "ReactiveArduinoLib.h"
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
FromRange<int>(0, 10)
>> Scale<int>(0, 10, 100, 200)
>> ToSerial<int>();
}
void loop()
{
}#include "ReactiveArduinoLib.h"
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
FromRange<int>(0, 10)
>> Scale<int>(100)
>> ToSerial<int>();
}
void loop()
{
}#include "ReactiveArduinoLib.h"
auto observableInt = FromProperty<int>();
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableInt
>> Millis<int>() // Millis() or Micros()
>> 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 = FromProperty<int>();
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableInt
>> ElapsedMillis<int>() // ElapsedMillis() or ElapsedMicros()
>> 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 = FromProperty<int>();
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableInt
>> Frequency<int>()
>> ToSerial<float>();
}
void loop()
{
delay(2000);
observableInt = 1;
}#include "ReactiveArduinoLib.h"
auto observableInt = FromProperty<int>();
void setup()
{
Serial.begin(9600);
while (!Serial) delay(1);
observableInt
>> Toggle<int>()
>> ToSerial<bool>();
}
void loop()
{
delay(1000);
observableInt = 1;
delay(1000);
observableInt = 2;
delay(1000);
observableInt = 2;
delay(1000);
observableInt = 3;
}#include "ReactiveArduinoLib.h"
// Emits ON when (OFF && x > 3)
// Emits OFF when (ON && x < 3)
// Results:
// Ignore 0, 1, 1, 2, 1
// EMITS SHOW ON at 5
// Ignore 4
// EMITS OFF at 2
// EMITS ON at 6
// EMITS OFF at 2
// EMITS ON at 4
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)
>> Threshold<int>(3)
>> ToSerial<bool>();
}
void loop()
{
}#include "ReactiveArduinoLib.h"
// Emits ON when (OFF && x > 4)
// Emits OFF when (ON && x < 3)
// Results:
// Ignore 0, 1, 1, 2, 1
// EMITS SHOW ON at 5
// Ignore 4
// EMITS OFF at 2
// EMITS ON at 6
// EMITS OFF at 2
// Ignore 4
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)
>> Threshold<int>(3, 4)
>> ToSerial<bool>();
}
void loop()
{
}#include "ReactiveArduinoLib.h"
auto reactiveInput = FromAnalogInput<int>(A0, INPUT_PULLUP);
void setup()
{
reactiveInput
>> AdcToVoltage<float>()
>> ToSerial<float>();
}
void loop()
{
reactiveInput.Next();
}