I2CMotor/src/I2CMotor.h
2025-05-18 13:38:58 +03:00

39 lines
1.0 KiB
C++

#ifndef I2C_MOTOR_H
#define I2C_MOTOR_H
#include <Arduino.h>
#include <Wire.h>
class I2CMotor {
public:
I2CMotor();
I2CMotor(uint8_t sda = 8, uint8_t scl = 3, uint32_t freq = 100000);
void begin();
bool found();
uint8_t address();
String identify();
void setDeviceName(const char* newname);
void setMinMax(uint8_t min_pwm, uint8_t max_pwm);
void setMotorDirection(uint8_t motor, uint8_t dir);
void setMotorSpeed(uint8_t motor, uint8_t speed_percent);
void allStop(); // Renamed from emergencyStop
// New: Set address at runtime
void setAddress(uint8_t addr);
// --- New functions for L298N motor control ---
bool motorControl(uint8_t motor, uint8_t speed_percent, uint8_t direction);
bool bothMotorsControl(uint8_t speedA, uint8_t dirA, uint8_t speedB, uint8_t dirB);
void stopAllMotors();
private:
uint8_t sda_, scl_;
uint32_t freq_;
uint8_t slave_addr_;
uint8_t scanForMotorController();
String queryIdentification(uint8_t addr);
};
#endif