-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 52f702f
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); // 等待时间 | ||
} | ||
} |