constrain(x, a, b)
描述
限制一数值于某范围内。
参数
x
: 须限制范围的数值,任意资料型别
a
: 限制范围的最小值,任意资料型别
b
: 限制范围的最大值,任意资料型别
回传
x
: 若 x
介于 a
和 b
之间
a
: 若 x
小于 a
b
: 若 x
大于 b
范例
sensVal = constrain(sensVal, 10, 150); // 将变数 sensVal 的数值限制在 10 到 150 之间
See also
本页由热血青年 LBU 译自英文版。
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.