wrap()
Restricts a value to an interval [low, high) by wrapping it around.
Code |
Result |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Two alternative versions are provided:
Version |
Equivalent to |
---|---|
|
|
|
|
Example
Ramp LED up and then back to zero once every 10 second:
#include <Plaquette.h>
AnalogOut led(9);
void begin() {
}
void step() {
wrap(seconds(), 10.0) >> led;
}
Reference
-
float pq::wrap(double x, double low, double high)
Restricts value to the interval [low, high) by wrapping it around.
- Parameters:
x – the value to wrap
low – the lower boundary
high – the higher boundary
- Returns:
the value wrapped around [low, high) or [high, low) if high < low
-
float pq::wrap(double x, double high)
Restricts value to the interval [0, high) by wrapping it around.
- Parameters:
x – the value to wrap
high – the higher bound
- Returns:
the value wrapped around [0, high) or [high, 0) if high is negative
-
float pq::wrap01(double x)
Restricts value to the interval [0, 1) by wrapping it around.
- Parameters:
x – the value to wrap
- Returns:
the value wrapped around [0, 1).