diff --git a/README.md b/README.md index 022a38a..349aaad 100644 --- a/README.md +++ b/README.md @@ -119,22 +119,38 @@ The I2CMotor offers exceptional versatility, as it can function as a standalone ### API Overview +| Method & Signature | Description | Example Usage | +|------------------------------------------------------|---------------------------------------------------------------------|---------------------------------------------| +| `begin()` | Initializes the I2C bus and prepares the library | `motor.begin();` | +| `setAddress(uint8_t addr)` | Sets the target slave I2C address for all subsequent commands | `motor.setAddress(0x08);` | +| `setDeviceName(const char* name)` | Sets the device name on the slave (stored in EEPROM) | `motor.setDeviceName("MyMotor");` | +| `identify()` | Requests and returns the identification string from the slave | `String id = motor.identify();` | +| `motorControl(uint8_t motor, uint8_t spd, uint8_t dir)` | Controls a single motor (1=A, 2=B), speed (0-100), direction (0=FWD, 1=REV) | `motor.motorControl(1, 80, 0);` | +| `bothMotorsControl(uint8_t sa, uint8_t da, uint8_t sb, uint8_t db)` | Controls both motors at once: speeds and directions | `motor.bothMotorsControl(100, 0, 80, 1);` | +| `stopAllMotors()` | Stops both motors (sets speed to 0) | `motor.stopAllMotors();` | +| `allStop()` | Emergency stop (hardware-level, all motors off) | `motor.allStop();` | +| `scanI2CBusForMotors()` (custom function) | Scans the I2C bus for compatible motor controllers | `scanI2CBusForMotors();` | +| `setSlaveAddress(uint8_t currAddr, uint8_t newAddr)` (custom function) | Sends address change command to the slave | `setSlaveAddress(0x08, 0x09);` | -| Function | Description | Parameters | Return Type | -|----------|-------------|------------|-------------| -| `I2CMotor()` | Default constructor. | – | – | -| `I2CMotor(uint8_t sda, uint8_t scl, uint32_t freq)` | Constructor with I2C pin and frequency configuration. | `sda` (I2C SDA pin), `scl` (I2C SCL pin), `freq` (I2C frequency) | – | -| `void begin()` | Initializes I2C communication and scans for the motor controller. | – | – | -| `bool found()` | Checks if a motor controller was found. | – | `bool` | -| `uint8_t address()` | Returns the detected motor controller I2C address. | – | `uint8_t` | -| `String identify()` | Requests and returns the identification string from the motor controller. | – | `String` | -| `void setDeviceName(const char* newname)` | Sets a new name for the motor controller. | `newname` (C-string) | – | -| `void setMinMax(uint8_t min_pwm, uint8_t max_pwm)` | Sets minimum and maximum PWM (speed) values. | `min_pwm`, `max_pwm` | – | -| `void setMotorDirection(uint8_t motor, uint8_t dir)` | Sets direction for a specified motor. | `motor` (motor number), `dir` (1: CW, 2: CCW) | – | -| `void setMotorSpeed(uint8_t motor, uint8_t speed_percent)` | Sets speed (as percentage) for a specified motor. | `motor` (motor number), `speed_percent` | – | -| `void emergencyStop()` | Sends an emergency stop command to the motor controller. | – | – | -| `uint8_t scanForMotorController()` | Scans the I2C bus for a compatible motor controller and returns its address. | – | `uint8_t` | -| `String queryIdentification(uint8_t addr)` | Requests and returns identification string for a given I2C address. | `addr` (I2C address) | `String` | +#### **Parameter Descriptions** + +- **motor**: 1 = Motor A, 2 = Motor B +- **spd / sa / sb**: Speed percentage (0-100) +- **dir / da / db**: Direction (0 = Forward, 1 = Reverse) +- **addr / currAddr / newAddr**: 7-bit I2C address (e.g., 0x08) + +#### **Typical Usage Flow** + +1. `motor.begin();` +2. `motor.setAddress(0x08);` +3. `motor.setDeviceName("TestMotor");` +4. `String id = motor.identify();` +5. `motor.motorControl(1, 80, 0);` +6. `motor.bothMotorsControl(100, 0, 80, 1);` +7. `motor.stopAllMotors();` +8. `motor.allStop();` +9. `scanI2CBusForMotors();` +10. `setSlaveAddress(0x08, 0x09);` *(then use new address for further commands)* ---