diff --git a/examples/Control/Control.ino b/examples/Control/Control.ino index 7007d6c..7495181 100644 --- a/examples/Control/Control.ino +++ b/examples/Control/Control.ino @@ -1,22 +1,54 @@ #include -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); } diff --git a/src/I2CMotor.h b/src/I2CMotor.h index 9915a1f..09c22dc 100644 --- a/src/I2CMotor.h +++ b/src/I2CMotor.h @@ -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();