Skip to content

Commit

Permalink
Merge pull request #3 from antoinepetty/create-begin-method
Browse files Browse the repository at this point in the history
Create begin method
  • Loading branch information
antoinepetty authored Apr 13, 2020
2 parents cfbb29b + d8bd08f commit 21cef45
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/rotateMotor/rotateMotor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=RMCS-220X
version=1.0.0
version=1.1.0
author=Antoine Petty
maintainer=Antoine Petty <arduino@antoinepetty.co.uk>
sentence=A library to facilitate the control of a Rhino RMCS-220X Servo Motor over i2c.
Expand Down
12 changes: 9 additions & 3 deletions src/RMCS-220X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -153,3 +157,5 @@ double RMCS220X::readGoToPositionInDegrees() {
void RMCS220X::goToRelativePositionInDegrees(double value) {
goToRelativePositionInSteps(stepsFromDegrees(value));
}


5 changes: 4 additions & 1 deletion src/RMCS-220X.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 21cef45

Please sign in to comment.