伺服电机的Arduino库函数
servo.attach(pin) //连接伺服电机的信号线于控制板的引脚,9或10号引脚
servo.attach(pin, min, max)
servo: a variable of type Servo
pin: the number of the pin that the servo is attached to
min (optional): the pulse width, in microseconds, corresponding to the minimum (0-degree) angle on the servo (defaults to 544)
max (optional): the pulse width, in microseconds, corresponding to the maximum (180-degree) angle on the servo (defaults to 2400)
Description:Attach the Servo variable to a pin. Note that in Arduino 0016 and earlier, the Servo library supports only servos on only two pins: 9 and 10.
servo.write(angle) ///用度控制伺服电机的角度,0-180度
angle: the value to write to the servo, from 0 to 180
Description:On a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement).
servo.writeMicroseconds(uS) //用微妙控制伺服电机角度,1000-1500-2000微妙
uS: the value of the parameter in microseconds (int)
Description:On standard servos a parameter value of 1000 is fully counter-clockwise, 2000 is fully clockwise, and 1500 is in the middle.
servo.read() //读取伺服电机的旋转角度,1-180度
Returnsthe angle of the servo, from 0 to 180 degrees.
Description:Read the current angle of the servo (the value passed to the last call to write())
servo.attached() //伺服电机信号线是否连接到控制板
Returnstrue if the servo is attached to pin; false otherwise.
Description:check whether the Servo variable is attached to a pin.
servo.detach() //解除伺服电机与控制板的信号连接
Description:Detach the Servo variable from its pin. If all Servo variables are detached, then pins 9 and 10 can be used for PWM output with analogWrite().
举例
1 #include <Servo.h>
2 Servo myservo;
3
4 void setup()
5 {
6 myservo.attach(9); // attach servo to pin 9
7 }
8
9 void loop()
10 {
11 if(myservo.attached()==true)
12 {
13 myservo.write(90); // set servo to mid-point
14 delay(10);
15 myservo.write(0); // set servo to 0 degree
16 delay(10);
17 myservo.write(180); // set servo to 180 degree
18 delay(20);
19
20 myservo.writeMicroseconds(1500); // set servo to mid-point
21 delay(10);
22 myservo.writeMicroseconds(1000); // set servo to 0 degree
23 delay(10);
24 myservo.writeMicroseconds(1500); // set servo to 180 degree
25 delay(20);
26 }
27 delay(2000);
28 myservo.detach();
29 }
运行效果
如果伺服电机连接到控制板,则先回到中点,再转到0度,再转到180度,重复循环一次,延时,解除伺服电机与控制板的连接。
伺服电机的Arduino库函数的更多相关文章
- 总线SPI的Arduino库函数
来源参考:https://www.cnblogs.com/MyAutomation/p/9348480.html 总线SPI的Arduino库函数 SPI基本知识 SPI:高速同步串行口.是一种标准的 ...
- OneWire总线的Arduino库函数
OneWire总线基本点 One-wire总线是DALLAS公司研制开发的一种协议,采用单根信号线,既传输时钟,又传输数据而且数据传输是双向的.它具有节省I/O 口线资源.结构简单.成本低廉.便于总线 ...
- I2C总线的Arduino库函数
I2C总线的Arduino库函数 I2C即Inter-Integrated Circuit串行总线的缩写,是PHILIPS公司推出的芯片间串行传输总线.它以1根串行数据线(SDA)和1根串行时钟线(S ...
- Arduino库函数中文说明
#define 常量名 常量值 % 取模运算符 String abc / char abc[n] 定义字符串 pinMode(pin,mode); 用于引脚的初始化 mode包括 INPUT ...
- arduino库函数1
https://wenku.baidu.com/view/e657b1f0bcd126fff6050baf.html 的阅读笔记.现在到了 第四十页. setup应该是 在开始 执行一次. 然后 lo ...
- 步进电机的Arduino库函数
This library allows you to control unipolar or bipolar stepper motors. To use it you will need a ste ...
- Arduino小车学习与研究
信安系统设计基础实践模块 Arduino小车学习与研究 ================== 陈都(20135328) 余佳源(20135321) 莫凡(20135225) ---------- 索引 ...
- Arduino小车学习与研究博客
Arduino小车学习与研究博客 信安系统设计基础实践模块 Arduino小车学习与研究 ================== 陈都(20135328) 余佳源(20135321) 莫凡(201352 ...
- AVR开发 Arduino方法(一) 端口子系统
Arduino UNO R3使用的主处理器ATMega328P上有3个8位的输入/输出端口,它们分别是PB,PC和PD.Arduino IDE提供的Blink示例可以帮助我们了解端口的数字输出功能: ...
随机推荐
- SpringCloud Alibaba Nacos 服务注册
业务服务接入Nacos服务治理中心 启动Nacos访问地址为:http://101.200.201.195:8848/nacos/ 创建bom工程用于管理依赖(下方附加源码地址) 准备工作完成后开始接 ...
- 为什么golang中不存在三元运算符
三元运算符广泛存在于其他语言中,比如: python: val = trueValue if expr else falseValue javascript: const val = expr ? t ...
- 深入了解Netty【四】IO模型
引言 IO模型就是操作数据输入输出的方式,在Linux系统中有5大IO模型:阻塞式IO模型.非阻塞式IO模型.IO复用模型.信号驱动式IO模型.异步IO模型. 因为学习Netty必不可少的要了解IO多 ...
- Axios拦截器配置
Axios 拦截器的配置如下 分三块:基础配置.请求之前拦截.响应之前拦截 发送所有请求之前和操作服务器响应数据之前对这种情况过滤. http request 请求拦截器 每次发送请求之前判断是否存在 ...
- Activiti7 流程部署
首先先绘制一个流程图 创建bpmn文件 然后绘制好节点 然后修改节点信息 指定负责人 点击背景,修改ID和名称 保存 然后重命名成xml 使用diagram打开 导出png 然后包xml改回bpmn ...
- 项目实战:Qt+Ffmpeg+OpenCV相机程序(打开摄像头、支持多种摄像头、分辨率调整、翻转、旋转、亮度调整、拍照、录像、回放图片、回放录像)
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- [oracle/sql]关于清除重复,not in方案和not exists方案的对比
有这样一张表: CREATE TABLE tb_sc ( id NUMBER not null primary key, studentid int not null, courseid int no ...
- leetcode刷题-51N皇后
题目 n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击. 给定一个整数 n,返回所有不同的 n 皇后问题的解决方案. 每一种解法包含一个明确的 n 皇后问 ...
- Promise核心实现
核心 构造函数核心 维护状态变量,只能由pending变为resolve或者reject 维护一个存储结果的变量 维护一个回调数组,执行到then,如果我们传入的立即执行函数没有立即执行resolve ...
- linux下查找文件中的某个关键字
1.方法一:grep '关键字' filename 2.方法二:vim filename进入文件里面,不要进入insert编辑模式,直接在normal模式下输入/关键字进行搜索 按n进行查找下一个