[Math]
描述
Constrains a number to be within a range.
語法
constrain(x, a, b)
參數
X
: the number to constrain, all data typesa
: the lower end of the range, all data typesb
: the upper end of the range, all data types
回傳
X
: if X
is between a
以及 b
a
: if X
is less than a
b
: if X
is greater than b
範例程式碼
sensVal = constrain(sensVal, 10, 150); // limits range of sensor values to between 10 and 150
參考
語法參考主頁面
86Duino 參考的文本是根據 Creative Commons Attribution-ShareAlike 3.0 License,部分文本是從 the Arduino reference 修改的。 參考中的代碼示例已發佈到公共領域。