hezhian hezhain / armtest

Fork of stepper by Xiaoyuan Yu

stepper.cpp

Committer:
Dennis_Yu
Date:
2018-07-25
Revision:
2:e537d08c705b
Parent:
1:bbb51c42e7d2
Child:
3:fd565358f888

File content as of revision 2:e537d08c705b:

#include "mbed.h"
#include "stepper.h"

void stepperMotor::moveStepper()
{
    if(remain == 0)
        return;
    if(step)
    {
        step = 0; //STEP 1->0
        remain--;
    }
    else
    {
        step = 1; //STEP 0->1
    }
}

void stepperMotor::enable()
{
    en = 0;
}

void stepperMotor::enable(int inputRemain)
{
    remain = inputRemain;
    enable();
}

void stepperMotor::disable()
{
    remain = 0;
    en = 1;
}

void stepperMotor::pause()
{
    en = 1;
}

void stepperMotor::setDir(bool direction)
{
    dir = direction;
}

stepperMotor::stepperMotor(PinName stepPin, PinName dirPin, PinName enPin, float period): remain(0), step(stepPin), dir(dirPin), en(enPin)
{
    disable();
    stepper.attach(this, &stepperMotor::moveStepper, period);
}