《单片机控制无刷电机(详细程序)——arduino源代码.doc》由会员分享,可在线阅读,更多相关《单片机控制无刷电机(详细程序)——arduino源代码.doc(3页珍藏版)》请在金锄头文库上搜索。
1、最近对arduino很感兴趣,因为它的开源,编写简单,用它来控制无刷电机。通过调节电位器来控制无刷电机的转速。程序是根据arduino中自带的Servo库改编而成!当然也是需要根据电调的通信协议PPM。电调PPM如图:#include Servo myservo; / create servo object to control a servo int potpin = 0; / analog pin used to connect the potentiometerint val; / variable to read the value from the analog pin boolea
2、n a = true; iiivoid setup() myservo.attach(9,1000,2000); / attaches the servo on pin 9 to the servo object void loop() if(a) delay(2500); myservo.writeMicroseconds(1000); delay(2000); a=false; 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