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