Servo

Servo

舵机(servo)介绍

​ 舵机是一种位置(角度)伺服的驱动器。舵机只是一种通俗的叫法,其实质是一个伺服马达。在需要角度不断变化并可以保持的控制系统中应用广泛。如遥控机械人、飞机模型等。舵机的转动角度为0~180°,其内部结构包括电机,控制电路和机械结构三部分。电机有三根线引出,分别接VCC、GNG和信号线。主要有两种引出线的格式:

棕、红、橙(棕色连接GND、红色连接VCC、橙色连接信号);
红、黑、黄(红色连接VCC、黑色连接GND、黄色连接信号)。

硬件连接图

Arduino 功能 舵机 功能
VCC 正极 红色 正极
GND 负极 棕色 负极
D9(PWM) 数字引脚(PWM) 橙色(信号传输) 信号输入

Servo_第1张图片

Servo库使用

github库

https://github.com/arduino-libraries/Servo/blob/master/examples/Sweep/Sweep.ino

头文件

#include  

Methods

  • attach()

    将Servo变量连接到销脚。请注意,在Arduino 0016和更早的版本中,Servo库只支持两个引脚上的伺服操作系统:9和10。

    Parameters
    servo.attach(pin) 
    servo.attach(pin, min, max)
    Parameters
    servo: a variable of type Servo
    pin: servo信号线连接主板的gpio
    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)
    
  • write()

    向Servo写入一个值,并相应地控制轴。在标准Servo系统上,这将设置轴的角度(以度),将轴移动到该方向。在连续旋转Servo上,这将设置Servo的速度(0在一个方向上为全速,180在另一个方向上为全速,接近90的值为无运动)。

    Parameters
    servo.write(angle)
    Parameters
    servo: a variable of type Servo
    angle: the value to write to the servo, from 0 to 180
    
  • writeMicroseconds()

    以微秒为单位(我们)给Servo,相应地控制轴。在一个标准的伺服系统上,这将设置轴的角度。在标准Servo系统上,参数值1000是完全逆时针,2000是完全顺时针,1500是在中间。

    请注意,有些制造商并不非常严格地遵循这个标准,因此伺服系统通常会响应于值在700到2300之间的值。请随意增加这些端点,直到伺服系统不再继续增加其范围。但是请注意,试图驱动伺服器超过其端点(通常由咆哮的声音表示)是一种大电流状态,应该避免。

    连续旋转Servo系统将以类似于写函数的方式响应写微秒函数。

    Syntax
    servo.writeMicroseconds(us)
    Parameters
    servo: a variable of type Servo
    us: the value of the parameter in microseconds (int)
    
  • read()

    读取Servo的当前角度(传递给最后一个调用以写入()的值)。

    Syntax
    servo.read()
    Parameters
    servo: a variable of type Servo
    Returns
    The angle of the servo, from 0 to 180 degrees.
    
  • attached()

    检查servo是否连接到一个gpio引脚上

    Syntax
    servo.attached()
    Parameters
    servo: a variable of type Servo
    Returns
    true if the servo is attached to pin; false otherwise.
    

example

#include 

Servo Varservo;
int pos;

setup()
{
	Varservo.attach(9);
}
loop()
{
	for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }

}

你可能感兴趣的:(arduino,linux,linux,drm,arduino)