constrain()

[Math]

描述

Constrains a number to be within a range.

語法

constrain(x, a, b)

參數

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: if X is between a 以及 b
a: if X is less than a
b: if X is greater than b

Example Code

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

參考

  • [程式語法] min()
  • [程式語法] max()

語法參考主頁面

86Duino 參考的文本是根據 Creative Commons Attribution-ShareAlike 3.0 License,部分文本是從 the Arduino reference 修改的。 參考中的代碼示例已發佈到公共領域。

發表評論

上部へスクロール