本库为配合牛明工作室的8通道电机驱动扩展板而设计的库。
在PlatformIO中使用本库,在platformio.ini中添加如下内容或者通过UI搜索BULLM_ExtendMotor添加即可
[env:myenv]
...
lib_deps =
bullm/BULLM_ExtendMotor
...在Arduino IDE中,直接在库管理器中搜索BULLM_ExtendMotor并安装即可。
#include <Wire.h>
#include <BULLM_ExtendMotor.h>
BULLM_ExtendMotor motor(0x7F); // 实例化,地址为0x7F
void setup() {
Wire.begin(4, 5); // 初始化I2C
motor.begin(); // 初始化
motor.setPWMFreq(1000); // 将PWM频率设置为1000Hz
motor.setSpeed(0, 255); // 设置第0通道电机的正转速度为255
motor.setSpeed(0, -255); // 设置第0通道电机的反转速度为255
}初始化
设置PWM频率
设置指定通道的速度
- index为通道号, 从1开始,1~8
- speed为速度值,范围为-255~255,正数表示正转,负数表示反转,0表示停止。
设置指定通道的速度,高精度
- index为通道号, 从1开始,1~8
- speed为速度值,范围为-4096~4096,正数表示正转,负数表示反转,0表示停止。
停止所有通道的电机