Articles Posted by the Author:

  • random()

    random()

    描述 random 函式会产生一个伪随机性的数字。 语法 random(max) random(min, max) 参数 min 随机值的下限,包含下限 (非必要) max 随机值的上限,不包含上限 回传 一个介于 min 到 max-1 之间的数字 (资料型别是 long) 注意 如果希望由 random() 产生的数字具有高随机性,在程式码中可以用 randomSeed() 去引入一个真正随机的输入,数值的随机性就如同 pin 脚上不接类比输入电压就呼叫 analogRead()。 相反的,它的伪随机性在需要重现相同行为时非常有用;可以在每一次开始随机序列之前呼叫 randomSeed() 并给它固定的参数值。 范例 See also - randomSeed() 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, […]


  • randomSeed(seed)

    randomSeed(seed)

    描述 randomSeed() 会初始化一个伪随机数字产生器,让它在随意一个点开始产生有顺序的乱数,这个顺序规律非常长而且随机性高。但此序列并不会改变,若是从同一个点开始,可以得到一样的数字。 如果希望由 random() 产生的数字具有高随机性,在程式码中可以用 randomSeed() 去引入一个真正随机的输入,数值的随机性就如同 pin 脚上不接类比输入电压就呼叫 analogRead()。 相反的,它的伪随机性在需要重现相同行为时非常有用;可以在每一次开始随机序列之前呼叫 randomSeed() 并给它固定的参数值。 参数 long, int 传一个数字去产生随机种子 回传 无回传值 范例 See also - random() 语法参考主页面 本页由热血青年 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 […]


  • sin(rad)

    sin(rad)

    描述 计算角度 (弧度) 的正弦值。结果将会在 -1.0 到 1.0 之间。 参数 rad: rad 代表弧度角,型别是 double。 回传 角度 (double 型别) 的正弦值。  See also - cos() - tan() - double 语法参考主页面 本页由热血青年 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 […]


  • cos(rad)

    cos(rad)

    描述 计算角度 (弧度) 的余弦。结果将会在 -1.0 到 1.0 之间。 参数 rad 代表弧度角,型别是double。 回传 角度 (double 型别) 的余弦。 See also - sin() - tan() - double 语法参考主页面 本页由热血青年 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 […]


  • tan(rad)

    tan(rad)

    描述 计算角度 (弧度) 的正切。结果将会在负无穷大到无穷大之间。 参数 rad 代表弧度角,型别是double。 回传 角度 (double 型别) 的正切 See also - sin() - cos() - double 语法参考主页面 本页由热血青年 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 […]


  • abs(x)

    abs(x)

    描述 计算出一个数值的绝对值。 参数 x: 欲计算的数值 回传 x: 若 x 大于或等于零 -x: 若 x 小于零 警告 由于 abs() 函式实作方法 (使用巨集) 的关系,在括号 () 中避免使用其他函式或运算,否则可能产生不正确的结果。 语法参考主页面 本页由热血青年 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 […]


  • constrain(x, a, b)

    constrain(x, a, b)

    描述 限制一数值于某范围内。 参数 x: 须限制范围的数值,任意资料型别 a: 限制范围的最小值,任意资料型别 b: 限制范围的最大值,任意资料型别 回传 x: 若 x 介于 a 和 b 之间 a: 若 x 小于 a b: 若 x 大于 b 范例 See also - min() - max() 语法参考主页面 本页由热血青年 LBU 译自英文版。 The text of the 86Duino reference is a modification of the Arduino reference, and is licensed […]


  • map(value, fromLow, fromHigh, toLow, toHigh)

    map(value, fromLow, fromHigh, toLow, toHigh)

    描述 将某个范围内的一个数值重新映射到另一个范围,亦即数值 fromLow 被映射到数值 toLow 去,而数值 fromHigh 则被映射到数值 toHigh, value 则维持与 fromLow、fromHigh 的比例关系映射至新的范围。 value 不一定是在范围内的数值,因为有时候超出范围的数值可能会有其他用处;如果希望数值限制在预期的范围内,可在该函式的前后使用函式 constrain()。 任一范围的下限是可以高于或低于范围的上限的,所以 map() 函式也可以用来反转一个范围内的数值,例如: y = map(x, 1, 50, 50, 1); 这个函式也可以处理负数,例如以下范例: y = map(x, 1, 50, 50, -100); 函式一样有效而且可以运作得很好。 map() 函式使用整数运算,所以不会有小数点,小数的部分会被舍去,而不是采用四舍五入做进位。 参数 value: 被映射的数字 fromLow: value 原本的范围下限 fromHigh: value 原本的范围上限 toLow: 要映射的目标范围下限 toHigh: 要映射的目标范围上限 回传 映射后的值 范例 延伸 关于数学上的计算运作,这里有一个完整的方程式: […]


  • pow(base, exponent)

    pow(base, exponent)

    描述 计算一个数字的乘方结果,pow() 也可以计算小数次方的乘方结果,这在计算数值或曲线的指数映射时是很有用的。 参数 base: 欲乘方的数字 (double) exponent: 向上乘的次方数 (double) 回传 数字乘方的结果 (double) 范例 请参考 Arduino 代码库中的 fscale 函式 See also - sqrt() - double 语法参考主页面 本页由热血青年 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 […]


  • sqrt(x)

    sqrt(x)

    描述 计算一个数字的平方根。 参数 x: double 型别的数字。 回传 数字的平方根,型别是 double。 See also - pow() 语法参考主页面 本页由热血青年 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.