2016-9-7 16:25:55 [显示全部楼层]
5070浏览
查看: 5070|回复: 1

[讨论] 【求助】关于舵机delay的问题

[复制链接]
如果每个舵机都要delay,如何同时控制几个舵机。

尝试了用 PT.h 多线程,效果不太好。

请问你们都是用什么方法控制舵机同时运行的,还有怎么控制舵机的运动速度呢?

随便贴点代码参考一下下~

主要想让几个舵机的速度都以很慢的速度运动

     Orz。



-stark  中级技师

发表于 2016-9-8 11:07:14

  1. #include <Servo.h>
  2. Servo myservo0;  // create servo object to control a servo
  3. Servo myservo1;
  4. Servo myservo2;                 
  5. Servo myservo3;
  6. Servo myservo4;
  7. Servo myservo5;
  8. int pos = 0;    // variable to store the servo position
  9. void setup()
  10. {
  11.   myservo0.attach(0);  // attaches the servo on pin 9 to the servo object
  12.   myservo1.attach(1);
  13.   myservo2.attach(2);
  14.   myservo3.attach(3);
  15.   myservo4.attach(4);
  16.   myservo5.attach(4);
  17. }
  18. void loop()
  19. {
  20.   for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  21.   {                                  // in steps of 1 degree
  22.     myservo0.write(pos);    // tell servo to go to position in variable 'pos'
  23.     myservo1.write(pos);
  24.     myservo2.write(pos);
  25.     myservo3.write(pos);
  26.     myservo4.write(pos);
  27.     myservo5.write(pos);
  28.     delay(10);                       // waits 15ms for the servo to reach the position
  29.   }
  30.   for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  31.   {                                
  32.     myservo0.write(pos);    // tell servo to go to position in variable 'pos'
  33.     myservo1.write(pos);
  34.     myservo2.write(pos);
  35.     myservo3.write(pos);
  36.     myservo4.write(pos);
  37.     myservo5.write(pos);
  38.     delay(10);                       // waits 15ms for the servo to reach the position
  39.   }
  40. }
复制代码


控制舵机速度就修改一下for里的delay时间
回复

使用道具 举报

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

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
关于楼主
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail