Set and check numeric quantile scales.
See Example Public Methods Release NotesSet and check numeric quantile scales. Provide an input domain and this library will convert it to a numeric quantile output range. This is different from the Arduino map() function because this library can handle a non-uniform input range.
This example takes an input domain of:
and converts it to the quantile output range:
#include <RBD_Threshold.h> RBD::Threshold threshold(3); // 3 levels void setup() { Serial.begin(115200); threshold.setLevel(1,0); // low threshold.setLevel(2,10.5); // medium threshold.setLevel(3,20); // high threshold.setMaxLevel(30); // max } void loop() { Serial.println(threshold.computeLevel(-1)); // 0 under Serial.println(threshold.computeLevel(8)); // 1 low Serial.println(threshold.computeLevel(10.6)); // 2 medium Serial.println(threshold.computeLevel(30)); // 3 high Serial.println(threshold.computeLevel(31)); // 4 over }
RBD::Threshold
Create a new instance and provide an integer for the maximum number of threshold levels. For example; set the level_count to 3 if you have levels of low, medium, and high. If you need more levels, this library will dynamically allocate an array to accommodate the size you provide the constructor.
RBD::Threshold threshold(3) // 3 levels void setup() { ... }
Provide an integer for a level index and an integer, float, or double for the threshold value. This is not zero based, the first level starts at 1. You must also call setMaxLevel() at the end to set an upper bounds of your last level.
void setup() { threshold.setLevel(1,0); // [0 - 10.49] threshold.setLevel(2,10.5); // [10.5 - 19.99] threshold.setLevel(3,20); // [20 - max] }
Provide an integer, float, or double to set the upper-bounds threshold of the last level.
void setup() { threshold.setMaxLevel(30); // [max = 30] }
Provide an integer for the level index, and this returns the value originally provided to setLevel().
void loop() { Serial.println(threshold.getLevel(3); // returns 20 }
Returns the value originally provided to setMaxLevel().
void loop() { Serial.println(threshold.getMaxLevel()); // returns 30 }
Provide an integer, float, or double value to compare against the thresholds for setLevel() and setMaxLevel(). This returns an integer for the computed level.
void loop() { Serial.println(threshold.computeLevel(17)); // returns 2 (medium) }