滑动电位器在类似于音量调节和参数调整这样的场所经常被使用到,其滑块能够滑动的距离称为行程,60行程即代表能够滑动60mm,是最常使用的一种行程大小。这个电子积木选用的就是60行程的滑动电位器:
使用上与其它基于电位器的电子积木一样,只需要用通用传感器连接线或者模拟传感器连接线,将其连接到某个模拟输入接口,如A5上:
然后再借助Arduino读出其值就可以,如下面的示例代码所示:
int sensorPin = 5; int value = 0; void setup() { Serial.begin(9600); } void loop() { value = analogRead(sensorPin); Serial.println(value, DEC); }
这样当滑块位于滑动电位器上的不同位置时,读出来的值会在0到1023间变连续变化。
No tags

ss · 2009/12/10 at 11:26 AM
好好想想要怎么用这个好东东