Skip to content

Commit

Permalink
Change getPwm and setPwm to getSpeed and setSpeed, bump major version
Browse files Browse the repository at this point in the history
  • Loading branch information
alextaujenis committed Nov 5, 2015
1 parent 89c38ef commit d6a6ecf
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Arduino Motor Library v1.1.1
#Arduino Motor Library v2.0.0
Control many motors without delay with commands like on(), off(), forward(), reverse(), and ramp().

* [Documentation](http://robotsbigdata.com/docs-arduino-motor.html)
Expand Down
2 changes: 1 addition & 1 deletion examples/forward_and_reverse/forward_and_reverse.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Arduino RBD Motor Library v1.1.1 Example - Spin a motor forward and reverse with events.
// Arduino RBD Motor Library v2.0.0 Example - Spin a motor forward and reverse with events.
// https://github.com/alextaujenis/RBD_Motor
// Copyright 2015 Alex Taujenis
// MIT License
Expand Down
2 changes: 1 addition & 1 deletion examples/spin_up_and_down/spin_up_and_down.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Arduino RBD Motor Library v1.1.1 Example - Spin a motor up and down with events.
// Arduino RBD Motor Library v2.0.0 Example - Spin a motor up and down with events.
// https://github.com/alextaujenis/RBD_Motor
// Copyright 2015 Alex Taujenis
// MIT License
Expand Down
Binary file modified extras/RBD_Motor.zip
Binary file not shown.
10 changes: 4 additions & 6 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ isOn KEYWORD2
isOff KEYWORD2
isForward KEYWORD2
isReverse KEYWORD2
getPwm KEYWORD2
getPwmPercent KEYWORD2
isPwm KEYWORD2
isPwmPercent KEYWORD2
setPwm KEYWORD2
setPwmPercent KEYWORD2
getSpeed KEYWORD2
getSpeedPercent KEYWORD2
setSpeed KEYWORD2
setSpeedPercent KEYWORD2
rampUp KEYWORD2
rampDown KEYWORD2
ramp KEYWORD2
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=RBD_Motor
version=1.1.1
version=2.0.0
author=Alex Taujenis <[email protected]>
maintainer=Alex Taujenis <[email protected]>
sentence=Control many motors without delay.
Expand Down
36 changes: 14 additions & 22 deletions src/RBD_Motor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Arduino RBD Motor Library v1.1.1 - Control many motors.
// Arduino RBD Motor Library v2.0.0 - Control many motors.
// https://github.com/alextaujenis/RBD_Motor
// Copyright 2015 Alex Taujenis
// MIT License
Expand Down Expand Up @@ -30,14 +30,14 @@ namespace RBD {
if(stop_everything) {
_stopEverything();
}
setPwm(255);
setSpeed(255);
}

void Motor::off(bool stop_everything) { // default: true
if(stop_everything) {
_stopEverything();
}
setPwm(0);
setSpeed(0);
}

void Motor::forward() {
Expand Down Expand Up @@ -148,38 +148,30 @@ namespace RBD {
}

bool Motor::isOn() {
return getPwm() == 255;
return getSpeed() == 255;
}

bool Motor::isOff() {
return getPwm() == 0;
return getSpeed() == 0;
}

int Motor::getPwm() {
int Motor::getSpeed() {
return _speed;
}

int Motor::getPwmPercent() {
return int((getPwm() / 255.0 * 100) + 0.5); // add 0.5 for correct rounding
int Motor::getSpeedPercent() {
return int((getSpeed() / 255.0 * 100) + 0.5); // add 0.5 for correct rounding
}

bool Motor::isPwm(int value) {
return getPwm() == value;
}

bool Motor::isPwmPercent(int value) {
return getPwmPercent() == value;
}

void Motor::setPwm(int value) {
void Motor::setSpeed(int value) {
if(value > -1 && value < 256) {
analogWrite(_pwm_pin, value);
_speed = value;
}
}

void Motor::setPwmPercent(int value) {
setPwm(int(value / 100.0 * 255));
void Motor::setSpeedPercent(int value) {
setSpeed(int(value / 100.0 * 255));
}

void Motor::rampUp(unsigned long timeout) {
Expand All @@ -192,7 +184,7 @@ namespace RBD {

void Motor::ramp(int value, unsigned long timeout) {
_stopEverything();
_start_speed = getPwm();
_start_speed = getSpeed();
_target_speed = value;

if(_speedShouldChange()) {
Expand Down Expand Up @@ -228,10 +220,10 @@ namespace RBD {

void Motor::_ramp() {
if(_timer.isActive()) {
setPwm(int(_start_speed + (_timer.getPercentValue() / 100.0 * _speedDifference())));
setSpeed(int(_start_speed + (_timer.getPercentValue() / 100.0 * _speedDifference())));
}
else {
setPwm(_target_speed);
setSpeed(_target_speed);
_stopRamping();
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/RBD_Motor.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Arduino RBD Motor Library v1.1.1 - Control many motors.
// Arduino RBD Motor Library v2.0.0 - Control many motors.
// https://github.com/alextaujenis/RBD_Motor
// Copyright 2015 Alex Taujenis
// MIT License
Expand All @@ -25,12 +25,10 @@ namespace RBD {
bool isOff();
bool isForward();
bool isReverse();
int getPwm();
int getPwmPercent();
bool isPwm(int value);
bool isPwmPercent(int value);
void setPwm(int value);
void setPwmPercent(int value);
int getSpeed();
int getSpeedPercent();
void setSpeed(int value);
void setSpeedPercent(int value);
void rampUp(unsigned long timeout);
void rampDown(unsigned long timeout);
void ramp(int value, unsigned long timeout);
Expand Down

0 comments on commit d6a6ecf

Please sign in to comment.