最近对 arduino 很感兴趣,因为它的开源,编写简单,用它来控
制电调。通过调节电位器来控制无刷电机的转速。程序是根据 arduino
中自带的 Servo 库中示例程序 knob 改编而成!当然也是根据电调的
通信协议 PPM 来修改的!如图:
程序代码:
#include
Servo myservo;
// create servo object to control a servo
int potpin = A0;
// analog pin used to connect the potentiometer
int val;
// variable to read the value from the analog pin
void setup()
{
myservo.attach(9,1000,2000);
// attaches the servo on pin 9 to
the servo object
delay(2500);
myservo.writeMicroseconds(1000);
delay(2000);
}
void loop()
{
val = analogRead(potpin);
// reads the value of the
potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179);
// 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
}
说明:A0 引脚接电位器来控制电机速度,9 引脚接电调的信号线,
电机启动后调节电位器由小逐渐调到最大,电机就开始由慢逐渐
变快旋转起来。