最近对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引脚接电调的信号线,电机启动后调节电位器由小逐渐调到最大,电机就开始由慢逐渐变快旋转起来。 本文来源:https://www.wddqw.com/doc/6c2537353968011ca3009119.html