伺服电机的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示例可以帮助我们了解端口的数字输出功能: ...
随机推荐
- 【转】mac上安装gradle
http://www.douban.com/note/311599602/ 首先,先download最新版本的gradle,网址如下:http://www.gradle.org/get-started ...
- 分布式文件存储:FastDFS简单使用与原理分析
引言 FastDFS 属于分布式存储范畴,分布式文件系统 FastDFS 非常适合中小型项目,在我接手维护公司图片服务的时候开始接触到它,本篇文章目的是总结一下 FastDFS 的知识点. 用了 2 ...
- [BUUOJ记录] [强网杯 2019]随便注(三种方法)
本题主要考察堆叠注入,算是比较经典的一道题,在i春秋GYCTF中也出现了本题的升级版 猜测这里的MySQL语句结构应该是: select * from words where id='$inject' ...
- C# 获取当前月的月初和月末
/// <summary> /// 获取当前月的月末日期 /// </summary> /// <returns></returns> public s ...
- C004:要求用户输入一个美元数量,然后显示出增加5%税率后的相应金额
程序: #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { float amount; do{ printf(&q ...
- oracle之三目录库和辅助库
目录库和辅助库 10.1 创建目录库(Catalog database)的必要性 如果没有catalog,RMAN的存储库(元数据)保存在目标库的控制文件里,这样可能存在如下隐患 1)目标库上的控制文 ...
- dict字典,以及字典的一些基本应用
dict表示方法: dict={}或d=dict() 1.字典的增:d['元素名']='元素值'.或d.setdefault('key','value') 2.字典的删:d.pop(key).或del ...
- [极客大挑战 2019]Havefun wp
很少见的很简单的一道题 查看源代码 获得一段被注释的代码 直接?cat=dog即可得flag
- 《Redis内存数据库》Redis数据类型和基本操作
前言 redis 有多种数据类型,兼容应用的开发. 说明 第一种数据类型:string(字符串) set key value -- 设置key和key对应的value值 get key ...
- netty字节分包
高并发压测时,发现来自网关的消息出现粘包现象:分包就是势在必行的 前置和处理平台(暂时)使用netty通话,由于都是服务器平台使用DelimiterBasedFrameDecoder来解决分包 和网关 ...