Arduino Servo 库使用教程

Arduino Servo 库使用教程

ServoServo Library for Arduino项目地址:https://gitcode.com/gh_mirrors/serv/Servo

1. 项目的目录结构及介绍

Arduino Servo 库的目录结构相对简单,主要包含以下几个部分:

Servo/
├── keywords.txt
├── library.properties
├── README.md
├── src/
│   └── Servo.h
│   └── Servo.cpp
  • keywords.txt: 定义了在 Arduino IDE 中高亮显示的关键词。
  • library.properties: 包含库的元数据,如名称、版本、作者等。
  • README.md: 项目的说明文档,通常包含安装和使用说明。
  • src/: 源代码目录,包含库的主要实现文件 Servo.hServo.cpp

2. 项目的启动文件介绍

在 Arduino Servo 库中,主要的启动文件是 src/Servo.h。这个文件定义了 Servo 类的接口和一些常量。以下是 Servo.h 文件的部分内容:

#ifndef Servo_h
#define Servo_h

#include <inttypes.h>

#define Servo_VERSION           2     // software version of this library

#define MIN_PULSE_WIDTH       544     // the shortest pulse sent to a servo  
#define MAX_PULSE_WIDTH      2400     // the longest pulse sent to a servo 
#define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached
#define REFRESH_INTERVAL    20000     // minumim time to refresh servos in microseconds

#define SERVOS_PER_TIMER       12     // the maximum number of servos controlled by one timer
#define MAX_SERVOS   SERVOS_PER_TIMER

class Servo {
  public:
    Servo();
    uint8_t attach(int pin);           // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
    uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes
    void detach();
    void write(int value);             // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
    void writeMicroseconds(int value); // Write pulse width in microseconds
    int read();                        // returns current pulse width as an angle between 0 and 180 degrees
    int readMicroseconds();            // returns current pulse width in microseconds for this servo (was read_us() in first release)
    bool attached();                   // return true if this servo is attached, otherwise false
  private:
    uint8_t servoIndex;                // index into the channel data for this servo
    int8_t pin;                        // PWM output pin number
};

#endif

3. 项目的配置文件介绍

在 Arduino Servo 库中,主要的配置文件是 library.properties。这个文件包含了库的基本信息,如名称、版本、作者等。以下是 library.properties 文件的内容:

name=Servo
version=1.1.8
author=Michael Margolis
maintainer=Arduino
sentence=Allows Arduino/Genuino boards to control a variety of servo motors.
paragraph=This library allows an Arduino/Genuino board to control RC (hobby) servo motors. Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees. Continuous rotation servos allow the rotation of the shaft to be set to various speeds.
category=Device Control
url=https://github.com/arduino-libraries/Servo
architectures=*
  • name: 库的名称。
  • version: 库的版本号。
  • author: 库的作者。
  • maintainer: 库的维护者。
  • sentence: 库的简短描述。
  • paragraph: 库的详细描述。
  • category: 库的分类。
  • url: 库的 GitHub 地址。
  • architectures: 支持的架构。

通过以上介绍,您可以更好地理解和使用 Arduino Servo 库。希望这个教程对您有所帮助!

ServoServo Library for Arduino项目地址:https://gitcode.com/gh_mirrors/serv/Servo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白威东

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值