diff options
author | Marti Bolivar <mbolivar@mit.edu> | 2010-10-25 21:15:28 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@mit.edu> | 2010-11-17 12:44:28 -0500 |
commit | 2d429e75ce69e77f8c95490ac03881ec9aa0354a (patch) | |
tree | a3b810a6c75625b07a4b976e5d1e319c60e19a6b /source/arduino/constrain.rst | |
parent | 30ac55d80c18e93f9c39a6dd850c10f9e7fd92ac (diff) | |
download | librambutan-2d429e75ce69e77f8c95490ac03881ec9aa0354a.tar.gz librambutan-2d429e75ce69e77f8c95490ac03881ec9aa0354a.zip |
arduino language reference nearing completion, properly CC-BY-SA 3.0 attributed
Diffstat (limited to 'source/arduino/constrain.rst')
-rw-r--r-- | source/arduino/constrain.rst | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/source/arduino/constrain.rst b/source/arduino/constrain.rst index 2769219..eb06122 100644 --- a/source/arduino/constrain.rst +++ b/source/arduino/constrain.rst @@ -1,3 +1,5 @@ +.. highlight:: cpp + .. _arduino-constrain: constrain(x, a, b) @@ -6,55 +8,55 @@ constrain(x, a, b) Description ----------- -Constrains a number to be within a range. - +(Macro) Constrains a number to be within a range. Parameters ---------- -x: the number to constrain, all data types - - - -a: the lower end of the range, all data types - - - -b: the upper end of the range, all data types +**x**: the number to constrain +**a**: the lower end of the range +**b**: the upper end of the range Returns ------- **x**: if **x** is between **a** and **b** - - **a**: if **x** is less than **a** - - **b**: if **x** is greater than **b** - - Example ------- :: + // limits range of sensor values to between 10 and 150: sensVal = constrain(sensVal, 10, 150); - // limits range of sensor values to between 10 and 150 +Warning +------- -See also --------- +Because of the way ``constrain()`` is implemented, avoid using other +functions or causing side effects inside the parentheses, as it may +lead to incorrect results:: + + constrain(x,a++,b); // avoid this - yields incorrect results + + constrain(x,a,b); // use this instead- + a++; // keep other math outside constrain() +Arduino Compatibility +--------------------- -- `min <http://arduino.cc/en/Reference/Min>`_\ () -- `max <http://arduino.cc/en/Reference/Max>`_\ () +Maple's implementation of ``constrain()`` is compatible with Arduino. +See also +-------- +- :ref:`min() <arduino-min>` +- :ref:`max() <arduino-max>` |