Wiring language support

Functions

static float map (float x, float in_min, float in_max, float out_min, float out_max)
 Linearly rescale a number from one range of values to another. More...
 
static float constrain (float x, float min_val, float max_val)
 Constrain a number to stay within a given range. More...
 
static float min (float x, float y)
 Returns the maximum of two numbers. More...
 
static float max (float x, float y)
 Returns the minimum of two numbers. More...
 

Detailed Description

These are functions found in the Wiring (Arduino) language which are not directly related to I/O but are provided as a convenience.

Function Documentation

static float map ( float  x,
float  in_min,
float  in_max,
float  out_min,
float  out_max 
)
inlinestatic

Linearly rescale a number from one range of values to another.

This function linearly scales values of x such that the range in_min to in_max at the input corresponds to the range out_min to out_max at the output. Values outside this range are extrapolated.

This function behaves identically to the function of the same name in Processing. It is also similar to the corresponding function in Arduino, except that it supports floating point values.

Parameters
xInput value to be mapped.
in_minLower bound of the input range.
in_maxUpper bound of the input range.
out_minLower bound of the output range.
out_maxUpper bound of the output range.
Returns
Rescaled value.
Examples:
analog-input/render.cpp, oscillator-bank/render.cpp, scope-analog/render.cpp, and tremolo/render.cpp.
static float constrain ( float  x,
float  min_val,
float  max_val 
)
inlinestatic

Constrain a number to stay within a given range.

This function constrains x to remain within the range min_val to max_val. Values of x outside this range are clipped to the edges of the range.

This function behaves identically to the function of the same name in Processing. It is also similar to the corresponding function in Arduino, except that it supports floating point values.

Parameters
xInput value to be constrained.
min_valMinimum possible value.
max_valMaximum possible value.
Returns
Constrained value.
static float min ( float  x,
float  y 
)
inlinestatic

Returns the maximum of two numbers.

Returns the maximum of two numbers

static float max ( float  x,
float  y 
)
inlinestatic

Returns the minimum of two numbers.

Returns the minimum of two numbers