智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 2476|回复: 0
打印 上一主题 下一主题

[控制器] arduino 控制无刷电调

[复制链接]

20

主题

42

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
2493

优秀会员奖章

QQ
威望
461
贡献
1996
兑换币
21
注册时间
2011-4-18
在线时间
18 小时
跳转到指定楼层
1#
发表于 2014-1-24 18:41:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#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



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-6-17 14:36 , Processed in 0.070882 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表