Skip to content

Support generic drivers for Stepper library #4257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Change of pin numbering
renumber the pin number argument names, e.g. start at motor_pin_0, to
prevent confusing between the argument names and the array positions
  • Loading branch information
skniazev committed Dec 17, 2015
commit 8ed5d414b589b4f4c2cd44368cf21949179ec119
52 changes: 26 additions & 26 deletions libraries/Stepper/src/Stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,49 +88,49 @@
* two-wire constructor.
* Sets which wires should control the motor.
*/
Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2)
Stepper::Stepper(int number_of_steps, int motor_pin_0, int motor_pin_1)
{
initMotor(number_of_steps, motor_pin_1, motor_pin_2,
initMotor(number_of_steps, motor_pin_0, motor_pin_1,
0, 0, 0, (unsigned char*)phasesMatrix2, 2, 4);
}

/*
* constructor for four-pin version
* Sets which wires should control the motor.
*/
Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
int motor_pin_3, int motor_pin_4)
Stepper::Stepper(int number_of_steps, int motor_pin_0, int motor_pin_1,
int motor_pin_2, int motor_pin_3)
{
initMotor(number_of_steps, motor_pin_1, motor_pin_2,
motor_pin_3, motor_pin_4,
initMotor(number_of_steps, motor_pin_0, motor_pin_1,
motor_pin_2, motor_pin_3,
0, (unsigned char*)phasesMatrix4, 4, 4);
}

/*
* constructor for five phase motor with five wires
* Sets which wires should control the motor.
*/
Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
int motor_pin_3, int motor_pin_4,
int motor_pin_5)
Stepper::Stepper(int number_of_steps, int motor_pin_0, int motor_pin_1,
int motor_pin_2, int motor_pin_3,
int motor_pin_4)
{
initMotor(number_of_steps, motor_pin_1, motor_pin_2,
motor_pin_3, motor_pin_4,
motor_pin_5, (unsigned char*)phasesMatrix5, 5, 10);
initMotor(number_of_steps, motor_pin_0, motor_pin_1,
motor_pin_2, motor_pin_3,
motor_pin_4, (unsigned char*)phasesMatrix5, 5, 10);
}

/*
* universal constructor for motors with maximum five wires
* Sets which wires should control the motor, pointer to the phases matrix, number of pins and phases.
*/
Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
int motor_pin_3, int motor_pin_4,
int motor_pin_5, unsigned char *phasesMatrix,
Stepper::Stepper(int number_of_steps, int motor_pin_0, int motor_pin_1,
int motor_pin_2, int motor_pin_3,
int motor_pin_4, unsigned char *phasesMatrix,
int pin_count, int phase_count)
{
initMotor(number_of_steps, motor_pin_1, motor_pin_2,
motor_pin_3, motor_pin_4,
motor_pin_5, phasesMatrix,
initMotor(number_of_steps, motor_pin_0, motor_pin_1,
motor_pin_2, motor_pin_3,
motor_pin_4, phasesMatrix,
pin_count, phase_count);
}

Expand Down Expand Up @@ -192,9 +192,9 @@ void Stepper::stepMotor(unsigned char thisPhase)
/*
* Initialize the motor
*/
void Stepper::initMotor(int number_of_steps, unsigned char motor_pin_1, unsigned char motor_pin_2,
unsigned char motor_pin_3, unsigned char motor_pin_4,
unsigned char motor_pin_5, unsigned char *phasesMatrix,
void Stepper::initMotor(int number_of_steps, unsigned char motor_pin_0, unsigned char motor_pin_1,
unsigned char motor_pin_2, unsigned char motor_pin_3,
unsigned char motor_pin_4, unsigned char *phasesMatrix,
unsigned char pin_count, unsigned char phase_count)
{
this->step_number = 0; // which step the motor is on
Expand All @@ -206,11 +206,11 @@ void Stepper::initMotor(int number_of_steps, unsigned char motor_pin_1, unsign
this->phase_count = phase_count;
// phasesMatrix is used by the stepMotor() method:
this->phasesMatrix = phasesMatrix;
this->motor_pin[0] = motor_pin_1;
this->motor_pin[1] = motor_pin_2;
this->motor_pin[2] = motor_pin_3;
this->motor_pin[3] = motor_pin_4;
this->motor_pin[4] = motor_pin_5;
this->motor_pin[0] = motor_pin_0;
this->motor_pin[1] = motor_pin_1;
this->motor_pin[2] = motor_pin_2;
this->motor_pin[3] = motor_pin_3;
this->motor_pin[4] = motor_pin_4;
for (unsigned char i = 0; i < this->pin_count; i++){
pinMode(this->motor_pin[i], OUTPUT); // setup the pins on the microcontroller
}
Expand Down
24 changes: 12 additions & 12 deletions libraries/Stepper/src/Stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@
class Stepper {
public:
// constructors:
Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2);
Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
int motor_pin_3, int motor_pin_4);
Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
int motor_pin_3, int motor_pin_4,
int motor_pin_5);
Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
int motor_pin_3, int motor_pin_4,
int motor_pin_5, unsigned char *phasesMatrix,
Stepper(int number_of_steps, int motor_pin_0, int motor_pin_1);
Stepper(int number_of_steps, int motor_pin_0, int motor_pin_1,
int motor_pin_2, int motor_pin_3);
Stepper(int number_of_steps, int motor_pin_0, int motor_pin_1,
int motor_pin_2, int motor_pin_3,
int motor_pin_4);
Stepper(int number_of_steps, int motor_pin_0, int motor_pin_1,
int motor_pin_2, int motor_pin_3,
int motor_pin_4, unsigned char *phasesMatrix,
int pin_count, int phase_count);

// speed setter method:
Expand All @@ -142,9 +142,9 @@ class Stepper {

private:
void stepMotor(unsigned char thisPhase);
void initMotor(int number_of_steps, unsigned char motor_pin_1, unsigned char motor_pin_2,
unsigned char motor_pin_3, unsigned char motor_pin_4,
unsigned char motor_pin_5, unsigned char *phasesMatrix,
void initMotor(int number_of_steps, unsigned char motor_pin_0, unsigned char motor_pin_1,
unsigned char motor_pin_2, unsigned char motor_pin_3,
unsigned char motor_pin_4, unsigned char *phasesMatrix,
unsigned char pin_count, unsigned char phase_count);

unsigned long step_delay; // delay between steps, in ms, based on speed
Expand Down