菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
71
0

ardunio+舵机

原创
05/13 14:22
阅读数 36446

橙色信号线  
红色正极 5V
棕褐色负极 GND

 

 

#include <Servo.h>

Servo myServo;  // 定义Servo对象来控制
int pos = 0;    // 角度存储变量

void setup() {
  myServo.attach(4,500,2500);  // 控制线连接数字4,设置脉冲范围为0.5ms~2.5ms
}

void loop() { 
 for (pos = 0; pos <= 180; pos ++) { // 0°到180°
    // in steps of 1 degree
    myServo.write(pos);              // 舵机角度写入
    delay(15);                       // 等待转动到指定角度
  } 
  delay(3000);//延时3s
  for (pos = 180; pos >= 0; pos --) { // 从180°到0°
    myServo.write(pos);              // 舵机角度写入
    delay(15);                       // 等待转动到指定角度
  }
  delay(5000);//延时3s 
}

 

相关热门文章

发表评论

0/200
71 点赞
0 评论
收藏
为你推荐 换一批