智能车制作
标题:
arduino 控制无刷电调
[打印本页]
作者:
294026416
时间:
2014-1-24 18:41
标题:
arduino 控制无刷电调
#include <Servo.h> //引入lib
Servo myservo; // 创建一个伺服电机对象
int command = 0;
int val=30;
void setup()
{Serial.begin(9600);
myservo.attach(9);
myservo.write(0);
Serial.println("Wait for your input!
to init...");
while(Serial.available() <= 0)
delay(1000);
Serial.println("strat...");
myservo.write(179); //173
delay(2000);
myservo.write(23); //32
delay(1000);
}
void loop()
{
if (Serial.available() >0) {
command=Serial.read();
Serial.println(val ) ;
}
if (command == 'w'){
val++;
// Serial.println(val ) ;
command = '\0'; }
if (command == 's'){
val--;
command = '\0';
}
myservo.write(val); // 设定伺服电机的位置
// 等待电机旋转到目标角度
}
测试视频
http://dl.vmall.com/c0jfkfflnc
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2