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.