【发布时间】:2019-11-24 13:01:37
【问题描述】:
我看过很多关于 pwn 和伺服电机编码的视频,但无法理解伺服电机代码在 arduino 中的工作原理。 我的主要困惑是以下代码中延迟的确切目的是什么。 当我们说servo.write(180);不是说要180度吗? 这里的延迟有什么用? 几毫秒会导致伺服器正常工作或抖动或振动不移动或不正确旋转等。
包括
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
【问题讨论】: