0
我有一個伺服器,將掃描從0到180度,然後回到0然而我不能使用delay()函數,因爲我需要掃描被運動傳感器中斷。我寫了一些代碼,但掃描不平滑,伺服有時會跳轉。我沒有做好什麼?在此先感謝arduino伺服器和延遲
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;
}
}