|
3#
樓主 |
發表於 2012-1-11 10:55:04
|
只看該作者
今天想出一個寫法,用的是ARDUINO的自帶MAP縮放函數,測試運動了瞞不錯。
void loop()
{
int x;
for(x = 0; x< =180; x+=2)
{ int pos1=map(x,0,180,90,120);
int pos2=map(x,0,180,30,60);
int pos3=map(x,0,180,20,50);
myservo1.write(pos1);
myservo2.write(pos2);
myservo3.write(pos3);
delay(10);
}
for(x = 180; x< =0; x+=2)
{ int pos1=map(x,180,0,120,90);
int pos2=map(x,180,0,60,30);
int pos3=map(x,180,0,50,30);
myservo1.write(pos1);
myservo2.write(pos2);
myservo3.write(pos3);
delay(10);
}
} |
|