跳转到内容

Arduino库

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

安装

PlatformIO

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

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

Arduino IDE

在Arduino IDE中,直接在库管理器中搜索BULLM_ExtendModule并安装即可。注意是BULLM_ExtendModule不是ExtendMotor

简单示例

c
#include <Arduino.h>
#include <Wire.h>
#include "BULLM_ExtendMos16.h"

BULLM_ExtendMos16 extend(0x7F);

void setup() {
    Wire.begin(); // 初始化I2C
    Serial.begin(9600);

    if (!extend.begin()) {
        Serial.println("BULLM_ExtendMos16 not found");
        return;
    }
    Serial.println("BULLM_ExtendMos16 found");

    extend.setPWMFreq(100); // 设置频率
    extend.closeAll(); // 关闭所有电机
}

void loop() {
    extend.setSpeed(0, 127); // 设置输出0的占空比为127
    delay(300);
    extend.setSpeed(0, 255); // 设置输出0的占空比为255
    delay(300);
    extend.closeAll();
    delay(200);
}

库开源地址