adjusted the library to give chance to user to be bale to select the i2c pins
This commit is contained in:
parent
9de0ff4ef3
commit
8fc2d6ad13
@ -1,22 +1,54 @@
|
||||
#include <I2CMotor.h>
|
||||
|
||||
I2CMotor motor;
|
||||
// User can change these pins as needed:
|
||||
#define SDA_PIN 8
|
||||
#define SCL_PIN 3
|
||||
#define I2C_FREQ 100000
|
||||
|
||||
I2CMotor motor(SDA_PIN, SCL_PIN, I2C_FREQ);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
motor.begin();
|
||||
|
||||
if (motor.found()) {
|
||||
Serial.print("Motor controller found at address 0x");
|
||||
Serial.println(motor.address(), HEX);
|
||||
Serial.println("Identification: " + motor.identify());
|
||||
motor.setMotorDirection(1, 1); // Motor 1 forward
|
||||
motor.setMotorSpeed(1, 50); // 50% speed
|
||||
} else {
|
||||
Serial.println("Motor controller not found!");
|
||||
if (!motor.found()) {
|
||||
Serial.println("No motor controller found. Halting.");
|
||||
while (1);
|
||||
}
|
||||
|
||||
motor.identify();
|
||||
|
||||
// Set device name and min/max PWM
|
||||
motor.setDeviceName("FM");
|
||||
motor.setMinMax(40, 255);
|
||||
|
||||
Serial.println("All tests complete.");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Add your control logic here
|
||||
// Set direction forward and test speeds
|
||||
motor.setMotorDirection(1, 1); // Motor 1, forward
|
||||
motor.setMotorSpeed(1, 50);
|
||||
delay(2000);
|
||||
motor.setMotorSpeed(1, 60);
|
||||
delay(2000);
|
||||
motor.setMotorSpeed(1, 80);
|
||||
delay(2000);
|
||||
motor.setMotorSpeed(1, 100);
|
||||
delay(2000);
|
||||
|
||||
// Set direction backward and test speeds
|
||||
motor.setMotorDirection(1, 2); // Motor 1, backward
|
||||
motor.setMotorSpeed(1, 50);
|
||||
delay(2000);
|
||||
motor.setMotorSpeed(1, 60);
|
||||
delay(2000);
|
||||
motor.setMotorSpeed(1, 80);
|
||||
delay(2000);
|
||||
motor.setMotorSpeed(1, 100);
|
||||
delay(2000);
|
||||
|
||||
// Stop
|
||||
motor.emergencyStop();
|
||||
delay(2000);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
class I2CMotor {
|
||||
public:
|
||||
I2CMotor(uint8_t sda = 8, uint8_t scl = 9, uint32_t freq = 100000);
|
||||
I2CMotor(uint8_t sda = 8, uint8_t scl = 3, uint32_t freq = 100000);
|
||||
|
||||
void begin();
|
||||
bool found();
|
||||
|
Loading…
x
Reference in New Issue
Block a user