【求助】关于舵机delay的问题
如果每个舵机都要delay,如何同时控制几个舵机。尝试了用 PT.h 多线程,效果不太好。
请问你们都是用什么方法控制舵机同时运行的,还有怎么控制舵机的运动速度呢?
随便贴点代码参考一下下~
主要想让几个舵机的速度都以很慢的速度运动
Orz。
#include <Servo.h>
Servo myservo0;// create servo object to control a servo
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
int pos = 0; // variable to store the servo position
void setup()
{
myservo0.attach(0);// attaches the servo on pin 9 to the servo object
myservo1.attach(1);
myservo2.attach(2);
myservo3.attach(3);
myservo4.attach(4);
myservo5.attach(4);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1)// goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo0.write(pos); // tell servo to go to position in variable 'pos'
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
myservo4.write(pos);
myservo5.write(pos);
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo0.write(pos); // tell servo to go to position in variable 'pos'
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
myservo4.write(pos);
myservo5.write(pos);
delay(10); // waits 15ms for the servo to reach the position
}
}
控制舵机速度就修改一下for里的delay时间
页:
[1]