aboutsummaryrefslogtreecommitdiffstats
path: root/source/arduino/constrain.rst
blob: 2769219d24bf6354f4901b979743f7e1d539c89d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
.. _arduino-constrain:

constrain(x, a, b)
==================

Description
-----------

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



Returns
-------

**x**: if **x** is between **a** and **b**



**a**: if **x** is less than **a**



**b**: if **x** is greater than **b**



Example
-------

::

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



See also
--------


-  `min <http://arduino.cc/en/Reference/Min>`_\ ()
-  `max <http://arduino.cc/en/Reference/Max>`_\ ()