我正在尝试制作一个两个伺服器同时旋转的项目。但是,我的代码不起作用。
#include <Servo.h>
Servo servo1; // servo control object
Servo servo2;
void setup()
{
servo1.attach(10);
servo2.attach(9);
}
void loop()
{
int pos0,pos360,i;
for(pos0=0,pos360=360,i=0;i<=360;pos0++,pos360--,i++){
servo2.write(pos0);
delay(20);
servo1.write(pos360);
delay(20);
}
}
答案 0 :(得分:2)
#include <Servo.h>
Servo ball1; //servo motor 1
Servo ball2; //servo motor 2
int i=100;
int j=70;
int w,e,k;
void setup() {
ball1.attach(3); //attach
ball2.attach(5); //attach
Serial.begin(9600);
delay(1000);
}
void loop() {
for(w=120,e=60,k=0;k<=60;w--,e++,k++)
{
ball1.write(w); //write
ball2.write(e); //write
delay(15);
}
}