我有一个伺服器,可以从 0 度扫描到 180 度然后回到 0,但是我不能使用 delay() 函数,因为我需要运动传感器来中断扫描。我写了一些代码,但是扫描并不顺畅,伺服有时会跳来跳去。我做错了什么?提前致谢
int x = 0;
void pivot(){
for (pos = 0; pos <= 180; pos += 5) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo_2.write(pos); // tell servo to go to position in variable 'pos'
//delay(15);
for (x; x<10; x++)
{
delay(1);
ping();
}
x=0;
}
for (pos = 180; pos >= 0; pos -= 5) { // goes from 180 degrees to 0 degrees
myservo_2.write(pos); // tell servo to go to position in variable 'pos'
//delay(15);
for (x; x<10; x++)
{
delay(1);
ping();
}
x=0;
}
}