Updated
This commit is contained in:
parent
97f01b932a
commit
e209cf0196
@ -1,11 +1,10 @@
|
||||
#include <I2CMotor.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// Define I2C pins and slave addresses
|
||||
#define SDA_PIN 8
|
||||
#define SCL_PIN 3
|
||||
#define INITIAL_SLAVE_ADDR 0x08
|
||||
#define NEW_SLAVE_ADDR 0x10
|
||||
#define INITIAL_SLAVE_ADDR 0x10
|
||||
#define NEW_SLAVE_ADDR 0x12
|
||||
|
||||
I2CMotor motor(SDA_PIN, SCL_PIN);
|
||||
|
||||
|
@ -18,11 +18,12 @@ String I2CMotor::identify() {
|
||||
}
|
||||
|
||||
void I2CMotor::setDeviceName(const char* newname) {
|
||||
uint8_t len = strlen(newname);
|
||||
Wire.beginTransmission(slave_addr_);
|
||||
Wire.write(0x06);
|
||||
Wire.write(len);
|
||||
Wire.write((const uint8_t*)newname, len);
|
||||
Wire.write(0x02); // CMD_SET_NAME (must match slave)
|
||||
for (uint8_t i = 0; i < strlen(newname); i++) {
|
||||
Wire.write(newname[i]);
|
||||
}
|
||||
Wire.write('\0'); // Ensure null-terminated string for slave
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
@ -74,7 +75,7 @@ uint8_t I2CMotor::scanForMotorController() {
|
||||
if (c == '\0') break;
|
||||
id += c;
|
||||
}
|
||||
if (id.length() && id.indexOf("dc motor") >= 0) {
|
||||
if (id.length() && id.indexOf("GENERIC") >= 0) {
|
||||
Serial.print("Found motor controller at 0x");
|
||||
Serial.print(addr, HEX);
|
||||
Serial.print(": ");
|
||||
|
Loading…
x
Reference in New Issue
Block a user