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库函数的更多相关文章

  1. 总线SPI的Arduino库函数

    来源参考:https://www.cnblogs.com/MyAutomation/p/9348480.html 总线SPI的Arduino库函数 SPI基本知识 SPI:高速同步串行口.是一种标准的 ...

  2. OneWire总线的Arduino库函数

    OneWire总线基本点 One-wire总线是DALLAS公司研制开发的一种协议,采用单根信号线,既传输时钟,又传输数据而且数据传输是双向的.它具有节省I/O 口线资源.结构简单.成本低廉.便于总线 ...

  3. I2C总线的Arduino库函数

    I2C总线的Arduino库函数 I2C即Inter-Integrated Circuit串行总线的缩写,是PHILIPS公司推出的芯片间串行传输总线.它以1根串行数据线(SDA)和1根串行时钟线(S ...

  4. Arduino库函数中文说明

    #define 常量名 常量值 % 取模运算符 String abc  /  char abc[n]  定义字符串 pinMode(pin,mode);  用于引脚的初始化  mode包括 INPUT ...

  5. arduino库函数1

    https://wenku.baidu.com/view/e657b1f0bcd126fff6050baf.html 的阅读笔记.现在到了 第四十页. setup应该是 在开始 执行一次. 然后 lo ...

  6. 步进电机的Arduino库函数

    This library allows you to control unipolar or bipolar stepper motors. To use it you will need a ste ...

  7. Arduino小车学习与研究

    信安系统设计基础实践模块 Arduino小车学习与研究 ================== 陈都(20135328) 余佳源(20135321) 莫凡(20135225) ---------- 索引 ...

  8. Arduino小车学习与研究博客

    Arduino小车学习与研究博客 信安系统设计基础实践模块 Arduino小车学习与研究 ================== 陈都(20135328) 余佳源(20135321) 莫凡(201352 ...

  9. AVR开发 Arduino方法(一) 端口子系统

    Arduino UNO R3使用的主处理器ATMega328P上有3个8位的输入/输出端口,它们分别是PB,PC和PD.Arduino IDE提供的Blink示例可以帮助我们了解端口的数字输出功能: ...

随机推荐

  1. Android Studio开发工具常用快捷键。部分总结,不全面,只包含新手可能少用的

    Android Studio开发工具常用快捷键.部分总结,不全面,只包含新手可能少用的 作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 首先说明,因为 ...

  2. 轮廓线DP

    轮廓线DP ​ 刚刚学了轮廓线DP,想了好久才懂. ​ 我的理解就是用一条线的状态去更新另一条线的状态,然后将格子填满. ​ 图中正方形即是要填东西(根据题意)的格子,红线的状态是由黑线转移过来的. ...

  3. Unity 移动平台自己编写Shader丢失问题

    问题一:使用AB加载资源,资源中包含有第三方shader,加载出的资源出现shader丢失的显示问题 这是因为Unity在打包的时候,会进行资源精简,默认情况下,是不会将第三方shader打包进入包体 ...

  4. 良许被百万大V安排得服服帖帖,还跟美女小姐姐合影了……

    大家好,我是良许. 很多人问我说,良许,你在工作之余还花这么多时间精力去写公众号运营自媒体,到底是为了什么? 其实原因很简单,就是想做个副业,万一到了 35 岁真的失业了,我至少还有另外一份收入,不至 ...

  5. Linux命令使用教程

    Linux 内核最初只是由芬兰人林纳斯·托瓦兹(Linus Torvalds)在赫尔辛基大学上学时出于个人爱好而编写的. Linux 的发行版说简单点就是将 Linux 内核与应用软件做一个打包. 目 ...

  6. 在react项目添加看板娘(react-live2d)

    有留意到看板娘这么个东西,简直就是我们程序员+动漫迷的挚爱.但是回观网上,大多只是在老旧的html的静态引入.vue甚至也有几个不怎么维护的,还是老旧的不行的SDK2.X的版本.这这这这!我们的rea ...

  7. 解决 Mac 上 Docker 无法直接 ping 通的问题

    解决 Mac 上 Docker 无法直接 ping 通的问题 原文连接 一.背景 Mac os Mojave 10.14.3 Docker Desktop community 2.3.0.4 二.问题 ...

  8. Go语言 | 并发设计中的同步锁与waitgroup用法

    今天是golang专题的第16篇文章,我们一起来聊聊golang当中的并发相关的一些使用. 虽然关于goroutine以及channel我们都已经介绍完了,但是关于并发的机制仍然没有介绍结束.只有go ...

  9. 万字详解 TDengine 2.0 数据复制模块设计

    ​导读:TDengine分布式集群功能已经开源,集群功能中最重要的一个模块是数据复制(replication),现将该模块的设计分享出来,供大家参考.欢迎大家对着设计文档和GitHub上的源代码一起看 ...

  10. Linux内存子系统——Locking Pages(内存锁定)

    该部分内容可以参考libc man page 3.5 LockingPages 概述 你可以让系统将特定的虚拟内存页与实际页帧相"关联",并保持这样的状态(称为锁定).该部分内存不 ...