aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/arduino/constrain.rst
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@mit.edu>2010-10-25 21:15:28 -0400
committerMarti Bolivar <mbolivar@mit.edu>2010-11-17 12:44:28 -0500
commit95783b750fda95f5f4c1fac00ab24da03b31b517 (patch)
tree2b0bf89c101aa58af5796fbe76c7ec98eebbb0a5 /docs/source/arduino/constrain.rst
parent3a9a119e9a8ce72c0e1b8fa4d3904bdf84ce355c (diff)
downloadlibrambutan-95783b750fda95f5f4c1fac00ab24da03b31b517.tar.gz
librambutan-95783b750fda95f5f4c1fac00ab24da03b31b517.zip
arduino language reference nearing completion, properly CC-BY-SA 3.0 attributed
Diffstat (limited to 'docs/source/arduino/constrain.rst')
-rw-r--r--docs/source/arduino/constrain.rst46
1 files changed, 24 insertions, 22 deletions
diff --git a/docs/source/arduino/constrain.rst b/docs/source/arduino/constrain.rst
index 2769219..eb06122 100644
--- a/docs/source/arduino/constrain.rst
+++ b/docs/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>`