跳转到内容

Arduino库

如果您不使用Arduino, 可以看看开发章节

安装

PlatformIO

在PlatformIO中使用本库,在platformio.ini中添加如下内容或者通过UI搜索BULLM_ExtendMotor添加

ini
[env:myenv]
...
lib_deps = 
  bullm/BULLM_ExtendMotor
...

Arduino IDE

在Arduino IDE中,直接在库管理器中搜索BULLM_ExtendMotor并安装即可。

简单示例

c++
#include <Wire.h>
#include "BULLM_ExtendMotor.h"

BULLM_ExtendMotor motor(0x7F); // 实例化,地址为0x7F

void setup() {
    Wire.begin(4, 5); // 初始化I²C
    motor.begin(); // 初始化
    motor.setPWMFreq(1000); // 将PWM频率设置为1000Hz
    motor.setSpeed(1, 255); // 设置第1通道电机的正转速度为255
}

库开源地址

本库基于Adafruit PWM Servo Driver Library进行的二次封装,感谢他们的开源工作