资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
最近对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 boolean 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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号