From 7cfbd79282c2314c1be5f96a0432dc479e94043a Mon Sep 17 00:00:00 2001 From: antoinepetty <36314396+antoinepetty@users.noreply.github.com> Date: Mon, 13 Apr 2020 12:43:23 +0100 Subject: [PATCH 1/2] Moving i2c begin into begin method --- src/RMCS-220X.cpp | 12 +++++++++--- src/RMCS-220X.h | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/RMCS-220X.cpp b/src/RMCS-220X.cpp index fdca2b1..1995a89 100644 --- a/src/RMCS-220X.cpp +++ b/src/RMCS-220X.cpp @@ -59,9 +59,13 @@ long RMCS220X::readAttr(byte command, int numberOfBytes) { return result; } -RMCS220X::RMCS220X(byte incomingi2cAddress) { - Wire.begin(); // join i2c bus - i2cAddress = incomingi2cAddress; // set motor address +RMCS220X::RMCS220X() { + // Empty constructor +} + +void RMCS220X::begin(byte incomingi2cAddress) { + Wire.begin(); // join i2c bus + i2cAddress = incomingi2cAddress; // set motor address } void RMCS220X::writeMaxSpeed(int maxSpeed) { @@ -153,3 +157,5 @@ double RMCS220X::readGoToPositionInDegrees() { void RMCS220X::goToRelativePositionInDegrees(double value) { goToRelativePositionInSteps(stepsFromDegrees(value)); } + + diff --git a/src/RMCS-220X.h b/src/RMCS-220X.h index af8e4a2..c86496c 100644 --- a/src/RMCS-220X.h +++ b/src/RMCS-220X.h @@ -42,7 +42,10 @@ class RMCS220X{ public: - RMCS220X(byte incomingi2cAddress); + RMCS220X(); + + /* connect to i2c bus */ + void begin(byte incomingi2cAddress); /* write the maximum speed of the motor (0 to 255) */ void writeMaxSpeed(int maxSpeed); From d8bd08ff2c81fdc12ea29fc49b5d9a6ad288180f Mon Sep 17 00:00:00 2001 From: antoinepetty <36314396+antoinepetty@users.noreply.github.com> Date: Mon, 13 Apr 2020 12:49:37 +0100 Subject: [PATCH 2/2] Update example and properties file --- examples/rotateMotor/rotateMotor.ino | 3 ++- library.properties | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/rotateMotor/rotateMotor.ino b/examples/rotateMotor/rotateMotor.ino index 3adcb95..546305a 100644 --- a/examples/rotateMotor/rotateMotor.ino +++ b/examples/rotateMotor/rotateMotor.ino @@ -3,12 +3,13 @@ #define ADDR 0x08 // Address of motor on i2c bus -RMCS220X motor = RMCS220X(ADDR); +RMCS220X motor; void setup() { Serial.begin(9600); Serial.println("Start program"); + motor.begin(ADDR); printDebugInfo(); Serial.println("Setting position to 0 deg"); diff --git a/library.properties b/library.properties index 288adfb..5c0fc77 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=RMCS-220X -version=1.0.0 +version=1.1.0 author=Antoine Petty maintainer=Antoine Petty sentence=A library to facilitate the control of a Rhino RMCS-220X Servo Motor over i2c.