Constrain()

From Microduino Wiki
Jump to: navigation, search
#define constrain(amt, low, high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))

Adjust to the interval.

If amt is less than low,, return low; if amt is bigger than high, return high; otherwise, return amt . It is generally used to constrain a value to a certain range.

For example:

sensVal = constrain(sensVal, 10, 150);
// limits range of sensor values to between 10 and 150 

[Return to Arduino Syntax Manual]