Skip to content

Commit

Permalink
舵机示例程序
Browse files Browse the repository at this point in the history
  • Loading branch information
511aj committed Jun 29, 2023
0 parents commit 52f702f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Servo_copy_20230629174747/Servo_copy_20230629174747.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


#include <Servo.h>

Servo mys; // Servo 是定义,mys是舵机的名字
// 很多开发板允许同时创建12个Servo对象

int pos = 0; // 角度变量

void setup() {
mys.attach(D4); // 舵机在D4引脚 上
Serial.begin(9600);
}

void loop() {
for (pos = 0; pos <= 180; pos += 2) { // 0度转到180度
// 每一步增加1度
mys.write(pos); // 告诉伺服电机达到'pos'变量的角度

delay(200); //等待时间
}
for (pos = 180; pos >= 0; pos -= 2) { // 180度转到0度
mys.write(pos); // 告诉伺服电机达到'pos'变量的角度

delay(200); // 等待时间
}
}

0 comments on commit 52f702f

Please sign in to comment.