/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer 连接电位器的模拟引脚
int val; // variable to read the value from the analog pin 变量从模拟引脚读取数值
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object 将9号引脚上的伺服附加到伺服对象
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
//读取电位计的值(从0到1023)
//将其缩放以与伺服系统一起使用(数值在0到180)
//根据缩放值设置伺服位置
//等待伺服系统到达那里